zoukankan      html  css  js  c++  java
  • Tkinter(十):Messagebox 弹窗

    效果:点击hit me后弹出对应的messagebox,有的messagebox会有返回值,比如Yes/No,True/False。

    然后通过返回值,进行对应的判断操作

    import tkinter as tk
    import tkinter.messagebox  # python3需要引入这个模块,不然会报错
    
    # 定义窗口
    window = tk.Tk()
    window.title('my window')  # 窗口title
    window.geometry('200x200')  # 窗口尺寸
    
    
    def hit_me():
        # tk.messagebox.showinfo(title='Hi', message='hahahaha')
        # tk.messagebox.showwarning(title='Hi', message='It is warning')
        # tk.messagebox.showerror(title='error', message='It is error')
        # tk.messagebox.askquestion(title='askquestion', message='It is askquestion')  # return Yes or No,可通过返回值进行判断操作
        # tk.messagebox.askyesno(title='askyesno', message='It is askyesno')  # return True or False,可通过返回值进行判断操作
        # tk.messagebox.askretrycancel(title='askretrycancel',
        #                              message='It is askretrycancel')  # return True or False,可通过返回值进行判断操作
        tk.messagebox.askokcancel(title='askokcancel', message='It is askokcancel')  # return True or False,可通过返回值进行判断操作
    
    
    tk.Button(window, text='hit me', command=hit_me).pack()
    
    window.mainloop()

    总结:

    1.根据需求选择对应的messagebox

    2.python3需要额外引入 tkinter.messagebox 模块,不然会报错

  • 相关阅读:
    算法复杂度
    购物网站简介
    算法的基本概念
    Visual Basic的启动与退出
    SQL Server 日志数据库清理办法
    jquery操作select详解(取值,设置选中)
    使用HttpClient连接WebAPI 转送JSON实体数据
    JQ 限制文本框 数字 小数 字母
    禁止调整自定义控件的尺寸
    C#异步编程(二):异步基础补充
  • 原文地址:https://www.cnblogs.com/ronyjay/p/13729278.html
Copyright © 2011-2022 走看看