Python -- Gui编程 -- Tkinter的使用 -- 对话框消息框
2014-05-04 16:43
816 查看
1.消息框
tkMessageBox.py
2.简单对话框
tkSimpleDialog.py
3.文件对话框
tkFileDialog.py
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()
相关文章推荐
- Python -- Gui编程 -- Tkinter的使用 -- 对话框消息框
- Python -- Gui编程 -- Tkinter的使用 -- 菜单与画布
- 鱼c笔记——Python的GUI编程(十七):Tkinter的标准对话框模块messagebox 、filedialog 和 colorchooser
- Python -- Gui编程 -- Qt库的使用 -- 菜单与对话框
- python GUI编程(Tkinter)简单使用
- Python -- Gui编程 -- Tkinter的使用 -- 基本控件
- 使用Tkinter做python的GUI编程
- 《Java程序设计》第16周周四:GUI编程及文件对话框的使用~作业
- 鱼c笔记——Python的GUI编程(六):Tkinter的Text组件
- python3.6 +tkinter GUI编程 实现界面化的文本处理工具
- Python GUI编程(Tkinter)
- Python GUI编程(Tkinter)
- Python编程使用tkinter模块实现计算器软件完整代码示例
- python GUI编程(Tkinter)
- python使用Tkinter编写GUI
- [置顶] python 通过GUI:Tkinter编程建立一个登录数据库的案例
- python的GUI编程(Tkinter库)(一)
- GUI编程及文件对话框的使用
- python GUI编程(Tkinter)
- 【pythonGUI专题】tkinter库的学习与使用(一)