Python -- Gui编程 -- Tkinter的使用 -- 对话框消息框
2024-10-21 13:34:46
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()
最新文章
- Hbase安装和错误
- MySQL免安装的配置
- 招聘 微软全球技术支持中心 sql server组
- 【codevs 1565】【SDOI 2011】计算器 快速幂+拓展欧几里得+BSGS算法
- 数据库连接池的选择 Druid
- \r\n的坑
- HDU 4630 No Pain No Game 树状数组+离线查询
- Android APP的安装路径
- fluentd结合kibana、elasticsearch实时搜索分析hadoop集群日志<;转>;
- IMP数据文件时ORA-00959错误分析
- 六、C# 派生
- 安卓tabhost和子Activity通信方法
- Phoenix(sql on hbase)简单介绍
- windows MySQL 安装
- C#利用UdpClient发送广播消息
- IOS KVO没有在delloc中移除导致奔溃
- excel快速访问工具栏和自定义选项卡
- Zabbix3.4-部署安装
- C#时间间隔
- Log4j 2.0 使用说明(1) 之HelloWorld
热门文章
- day13(反射,BeanUtils包)
- D3_book 11.3 force
- java中的static(包括类前面修饰的static、方法前面修饰的static、成员变量前面修饰的static)
- 【转】Swig Getting Started
- linux系统编程之文件与IO(二):系统调用read和write
- django drf 动态权限配置和动态seriaizer_class配置
- 【cocos2d-x + Lua(1) 绑定Lua并使用tolua++】
- 使用Spring Boot,Spring Cloud和Docker实现微服务架构
- Java基础学习篇---------多线程
- const的详解