Tkinter教程之messagebox 弹窗

51changxuePython评论2,372 views阅读模式

Tkinter教程之messagebox 弹窗

import tkinter as tk
import tkinter.messagebox
import tkinter.filedialog
from tkinter import colorchooser

window = tk.Tk()
window.title('my window')
window.geometry('200x200')

def hit_me():
    tk.messagebox.showinfo(title='Hi', message='hahahaha')   # return 'ok',提示消息框
    tk.messagebox.showwarning(title='Hi', message='nononono')   # return 'ok',消息警告框
    tk.messagebox.showerror(title='Hi', message='No!! never')   # return 'ok',错误消息框
    print(tk.messagebox.askquestion(title='Hi', message='hahahaha'))   # return 'yes' , 'no'
    print(tk.messagebox.askyesno(title='Hi', message='hahahaha'))   # return True, False
    print(tk.messagebox.askretrycancel(title='Hi', message='hahahaha'))   # return True, False
    print(tk.messagebox.askokcancel(title='Hi', message='hahahaha'))   # return True, False
    print(tk.messagebox.askyesnocancel(title="Hi", message="haha"))     # return, True, False, None

'''filedialog  文件对话框
用来获取文件路径和文件名'''
def readfile():
    tkinter.filedialog.askopenfilename(title='打开CGNS文件',initialdir='C:\\',filetypes=[('CGNSdat', '*.dat'), ('All Files', '*')])
''' self.file_opt = options = {}
        options['defaultextension'] = '.txt'
        options['filetypes'] = [('all files', '.*'), ('text files', '.txt')]
        options['initialdir'] = 'C:\\'
        options['initialfile'] = 'myfile.txt'
        options['parent'] = root
        options['title'] = 'This is a title'
'''
def readcolor():
    print(tkinter.colorchooser.askcolor())
    print(tkinter.colorchooser.askcolor()[1])
    #第一个返回的是浮点数RGU,第二个是16进制
tk.Button(window, text='hit me', command=hit_me).pack()
tk.Button(window, text='readfile', command=readfile).pack()
tk.Button(window, text='readcolor', command=readcolor).pack()


window.mainloop()

运行结果:

Tkinter教程之messagebox 弹窗

继续阅读
51changxue
  • 本文由 发表于 2018年4月10日 00:35:35
  • 转载请务必保留本文链接:https://51changxue.com/455.html
pycharm永久破解激活教程 Python

pycharm永久破解激活教程

PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具,比如调试、语法高亮、Project管理、代码跳转、智能提示、自动完成、...
Tkinter控件快速引用总结 Python

Tkinter控件快速引用总结

  文件名称: Tkinter控件快速引用总结代码.rar 文件大小: 4k 更新日期: 2018-7-29 文件版本: V1.0 免责声明: 本站大部分下载资源收集于网络,只做学习和交流使...
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定