zoukankan      html  css  js  c++  java
  • messagebox

     1 """messagebox消息框"""
     2 import tkinter as tk
     3 #导入messagebox
     4 import tkinter.messagebox as messagebox
     5 window = tk.Tk()
     6 window.title("My Window")
     7 window.geometry("400x400")
     8 var = tk.StringVar()
     9 var.set("Hello world")
    10 label = tk.Label(window,textvariable=var,font=("斜体",15),width=20,height=2,bg="black",fg="green")
    11 label.pack()
    12 def hit_me():
    13     global label #使用全局变量
    14     messagebox.showinfo(title="info",message="提示")
    15     messagebox.showwarning(title="warning",message="警告")
    16     messagebox.showerror(title="error",message="错误")
    17     """return yes or no"""
    18     question = messagebox.askquestion(title="question",message="问题")
    19     if question == "yes":
    20         var.set("you selection yes")
    21     else:
    22         var.set("you selection no")
    23     """return True or False"""
    24     askyesno = messagebox.askyesno(title="yes or no",message="选择")
    25     if askyesno == True:
    26         var.set("You selection True")
    27     else:
    28         var.set("You selection False")
    29     """return True or False"""
    30     askokcancel = messagebox.askokcancel(title="cancel",message="取消")
    31     if askokcancel == True:
    32         var.set("You selection cancel")
    33     else:
    34         var.set("You don't selection cancel")
    35     """return True False None"""
    36     result = messagebox.askyesnocancel(title="continue",message="Hello World")
    37     if result == True:
    38         var.set("You selection yes")
    39     elif result == False:
    40         var.set("You selection no")
    41     elif result == None:
    42         var.set("You selection cancel")
    43     """return True False"""
    44     try_cancel = messagebox.askretrycancel(title="try_cancel",message="Hello World")
    45     if try_cancel == True:
    46         var.set("You selection retry")
    47     else:
    48         var.set("You selection cancel")
    49 button = tk.Button(window,text="hit_me",command=hit_me,fg="red",bg="green")
    50 button.pack()
    51 window.mainloop()
    
    
  • 相关阅读:
    01 mybatis框架整体概况(2018.7.10)-
    第一课(2018.7.10)
    JavaEE 企业级分布式高级架构师课程_汇总贴
    5-1条件运算符 & 5-2
    5-3运算符的优先级
    4-3逻辑非运算符及案例 & 4-4
    4-1逻辑与运算符介绍 & 4-2逻辑或运算符介绍
    3-3if-else条件结构 & 3-4 & 3-5
    3-2if条件结构
    3-1关系运算符
  • 原文地址:https://www.cnblogs.com/py-peng/p/10327747.html
Copyright © 2011-2022 走看看