1.消息框

tkMessageBox.py

 import tkinter
 from tkinter import messagebox

 def cmd():
     global n
     global buttontext
     n += 1
     if n==1:
         messagebox.askokcancel('Python Tkinter', 'askokcancel')
         buttontext.set('askquestion')
     elif n==2:
         messagebox.askquestion('Python Tkinter', 'askquestion')
         buttontext.set('askyesno')
     elif n==3:
         messagebox.askyesno('Python Tkinter', 'askyesno')
         buttontext.set('showerror')
     elif n==4:
         messagebox.showerror('Python Tkinter', 'showerror')
         buttontext.set('showinfo')
     elif n==5:
         messagebox.showinfo('Python Tkinter', 'showinfo')
         buttontext.set('showwarning')
     else:
         n = 0
         messagebox.showwarning('Python Tkinter', 'showwarning')
         buttontext.set('askokcancel')

 n = 0
 root = tkinter.Tk()
 buttontext = tkinter.StringVar()
 buttontext.set('askokcancel')
 button = tkinter.Button(root, textvariable=buttontext, command=cmd)
 button.pack()
 root.mainloop()

2.简单对话框

tkSimpleDialog.py

 import tkinter
 from tkinter import simpledialog

 def inputStr():
     r = simpledialog.askstring('Python Tkinter', 'Input String', initialvalue = 'Python Tkinter')
     print(r)
 def inputInt():
     r = simpledialog.askinteger('Python Tkinter', 'Input Integer')
     print(r)
 def inputFloat():
     r = simpledialog.askfloat('Python Tkinter', 'Input Float')
     print(r)

 root = tkinter.Tk()
 btn1 = tkinter.Button(root, text='Input String', command=inputStr)
 btn2 = tkinter.Button(root, text='Input Integer', command=inputInt)
 btn3 = tkinter.Button(root, text='Input Float', command=inputFloat)

 btn1.pack(side='left')
 btn2.pack(side='left')
 btn3.pack(side='left')

 root.mainloop()

3.文件对话框

tkFileDialog.py

 import tkinter
 from tkinter import filedialog

 def openfile():
     r = filedialog.askopenfilename(title='打开文件', filetypes=[('Python', '*.py *.pyw'), ('All Files', '*')])
     print(r)
 def savefile():
     r = filedialog.asksaveasfilename(title='保存文件', initialdir='d:\mywork', initialfile='hello.py')
     print(r)

 root = tkinter.Tk()
 btn1 = tkinter.Button(root, text='File Open', command=openfile)
 btn2 = tkinter.Button(root, text='File Save', command=savefile)

 btn1.pack(side='left')
 btn2.pack(side='left')
 root.mainloop()

最新文章

  1. Hbase安装和错误
  2. MySQL免安装的配置
  3. 招聘 微软全球技术支持中心 sql server组
  4. 【codevs 1565】【SDOI 2011】计算器 快速幂+拓展欧几里得+BSGS算法
  5. 数据库连接池的选择 Druid
  6. \r\n的坑
  7. HDU 4630 No Pain No Game 树状数组+离线查询
  8. Android APP的安装路径
  9. fluentd结合kibana、elasticsearch实时搜索分析hadoop集群日志<转>
  10. IMP数据文件时ORA-00959错误分析
  11. 六、C# 派生
  12. 安卓tabhost和子Activity通信方法
  13. Phoenix(sql on hbase)简单介绍
  14. windows MySQL 安装
  15. C#利用UdpClient发送广播消息
  16. IOS KVO没有在delloc中移除导致奔溃
  17. excel快速访问工具栏和自定义选项卡
  18. Zabbix3.4-部署安装
  19. C#时间间隔
  20. Log4j 2.0 使用说明(1) 之HelloWorld

热门文章

  1. day13(反射,BeanUtils包)
  2. D3_book 11.3 force
  3. java中的static(包括类前面修饰的static、方法前面修饰的static、成员变量前面修饰的static)
  4. 【转】Swig Getting Started
  5. linux系统编程之文件与IO(二):系统调用read和write
  6. django drf 动态权限配置和动态seriaizer_class配置
  7. 【cocos2d-x + Lua(1) 绑定Lua并使用tolua++】
  8. 使用Spring Boot,Spring Cloud和Docker实现微服务架构
  9. Java基础学习篇---------多线程
  10. const的详解