messagebox (python2中为tkMessageBox ):消息框,就是我们平时看到的弹窗。 需要定义一个触发功能,来触发这个弹窗,这里就用上前面学过的Button按钮,通过command调用功能,弹出各种类型的提示对话框。
 
示例:
import Tkinter as tk 
from tkMessageBox import * 
# 此处是python2.7的用法,python3.x要改为:from tkinter.messagebox import *,注意大小写
window = tk.Tk()
window.title('My Window')
window.geometry('500x300')  
 
def hit_me():
    showinfo(title='Hi', message='正常文本')            # 提示信息对话窗
    showwarning(title='Hi', message='有警告!')      # 提出警告对话窗
    showerror(title='Hi', message='出错了!')          # 提出错误对话窗
    askquestion(title='Hi', message='你好!')          # 询问选择对话窗return 'yes', 'no'
    askyesno(title='Hi', message='你好!')              # return 'True', 'False'
    askokcancel(title='Hi', message='你好!')         # return 'True', 'False'
 
l=tk.Button(window, text='hit me', bg='green', font=('Arial', 14), command=hit_me)
l.pack()
 
window.mainloop()
 
 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-29
  • 2021-09-29
  • 2021-06-06
  • 2021-07-27
猜你喜欢
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
  • 2021-04-29
  • 2021-12-18
  • 2022-12-23
相关资源
相似解决方案