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 模块,不然会报错

  • 相关阅读:
    .net证书Rsa加密
    $.ajax
    EF通用CRED
    JSON.pase()
    mysql 使用EF6.0CodeFirst
    jenkins 自动构建——shell脚本
    nginx配置示例
    easyui 随笔
    javascript 随笔
    asp.net mvc4 过滤器的简单应用:登录验证
  • 原文地址:https://www.cnblogs.com/ronyjay/p/13729278.html
Copyright © 2011-2022 走看看