【发布时间】:2020-06-15 11:58:06
【问题描述】:
Please kick here to see the current output and expected output
我有一个简单的 python 程序,我想默认取消选中复选按钮。我希望以与用户取消选中复选框时相同的方式查看它。请告诉我如何实现它。
from tkinter import *
from tkinter import ttk
def urgentReq():
global box
state = box.state()
if(box.instate(['selected'])):
print ("--> Urgent: ",state)
else:
print ("--> Not Urgent:",state)
gui = Tk()
gui.title("GUI")
gui.geometry('200x150')
box = ttk.Checkbutton(gui, text ='Urgent Request', command=lambda: urgentReq())
box.grid(column=1, row=4, pady=40, sticky="N")
#write something here to unselect the box by default
【问题讨论】:
-
当我运行您的代码时,
Checkbutton是最初未选中。
标签: python tkinter ttk tkinter.checkbutton ttkwidgets