Python -- Gui编程 -- Tkinter的使用 -- 对话框消息框
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()

Python -- Gui编程 -- Tkinter的使用 -- 对话框消息框的更多相关文章
- Python GUI编程(Tkinter) windows界面开发
Python实现GUI简单的来说可以调用Tkinter库,这样一般的需求都可以实现,显示简单的windows窗口代码如下: python_gui.py 1 #!C:\Python27\python.e ...
- Python GUI编程--Tkinter
今天看到了GUI编程,书上推荐用wxPython,去官网上看了看,发现Windows的最高支持到2.7,我用的是3.4版本,咋办,用自带的库--Tkinter呗,它是Python的默认GUI库,几乎是 ...
- python GUI编程tkinter示例之目录树遍历工具
摘录 python核心编程 本节我们将展示一个中级的tkinter应用实例,这个应用是一个目录树遍历工具:它会从当前目录开始,提供一个文件列表,双击列表中任意的其他目录,就会使得工具切换到新目录中,用 ...
- Python -- Gui编程 -- Tkinter的使用 -- 基本控件
1.按钮 tkBtton.py import tkinter root = tkinter.Tk() btn1 = tkinter.Button(root, anchor=tkinter.E,\ te ...
- Python GUI编程(Tkinter)(一)
tk官网的教程学习: https://tkdocs.com/tutorial/firstexample.html 学习blog: https://www.cnblogs.com/aland-1415/ ...
- Python GUI编程(Tkinter)Ⅱ
Tkinter 组件 Tkinter的提供各种控件,如按钮,标签和文本框,一个GUI应用程序中使用.这些控件通常被称为控件或者部件. 目前有15种Tkinter的部件.我们提出这些部件以及一个简短的介 ...
- Python -- Gui编程 -- Tkinter的使用 -- 菜单与画布
1.菜单 tkMenu.py import tkinter root = tkinter.Tk() menu = tkinter.Menu(root) submenu = tkinter.Menu(m ...
- Python之GUI编程(Tkinter))
不足之处,还请海涵,请指出不足.本人发布过的文章,会不断更改,力求减少错误信息. 一.重要放在开头:模块 如出现这种错误 ModuleNotFoundError: No module named 'n ...
- python大法好——ython GUI编程(Tkinter)
Python GUI编程(Tkinter) Python 提供了多个图形开发界面的库,几个常用 Python GUI 库如下: Tkinter: Tkinter 模块(Tk 接口)是 Python 的 ...
随机推荐
- 使用idea,springboot,springsession,redis实现分布式微服务的session 共享
本次开发环境:idea2016.3.4 +jdk1.8+maven3.3.9+redis+springboot+jedis 本文中的项目使用Maven来管理项目依赖,使用Spring Session和 ...
- hdu 5036 概率+bitset
http://acm.hdu.edu.cn/showproblem.php?pid=5036 n个房间每个房间里面有一把或多把钥匙可以打开其他的门.如果手上没有钥匙可以选择等概率随机选择一个门炸开,求 ...
- hdu 5024 最长的L型
http://acm.hdu.edu.cn/showproblem.php?pid=5024 找到一个最长的L型,L可以是斜着的 简单的模拟 #include <cstdio> #incl ...
- onclick传参
var tema="<a title='打开' href='javascript:;' onclick='showKnowledgeMap(1,\" "+kl_na ...
- gdb用法
mickole@test:~/ctest/05gdb$ gdb simple //开始gdb调试 GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4- ...
- NavigationViewController页面间通信及传值
使用进行页面跳转时,应该使用方法来跳转至下一页面,这样的话,下一页面同样在容器中. 1AloneSetPrizeViewController *setPrize = [[AloneSetPrizeVi ...
- FLV文件格式官方规范详解
——如果要学习一个新的知识点,官方手册可能是最快的途径.查看网上其他人的总结也许入门更快,但是要准确,深入,完整,还是要看官方手册. 以下内容来自对官方文档Video File Format Sp ...
- 打开SQL2008R2配置工具,提示远程调用失败[0x800706be]
卸载了Microsoft SQL Server 2012 Express LocalDB,依然不行. 再卸载Microsoft SQL Server 2014 LocalDB,此时右边显示框已可以显示 ...
- WPF 自定义下拉列表
XAML代码: <Popup x:Name="popupStrategy" StaysOpen="False" PopupAnimation=" ...
- python 函数中使用全局变量
python 函数中如果需要使用全局变量,需要使用 global + 变量名 进行声明, 如果不声明,那么就是重新定义一个局部变量,并不会改变全局变量的值 n [1]: a = 3 In [2]: d ...