Python 3.x 如何确定我是否按下了检查按钮? 从Tkinter导入* window=Tk() window.config(background=“green”) window.bind(“,退出) cbttn=Checkbutton(text=“Caps?”).grid(行=3,列=0)
如果cbttn=True,Python 3.x 如何确定我是否按下了检查按钮? 从Tkinter导入* window=Tk() window.config(background=“green”) window.bind(“,退出) cbttn=Checkbutton(text=“Caps?”).grid(行=3,列=0),python-3.x,tkinter,Python 3.x,Tkinter,如果cbttn=True,是否适用?或者我必须移动.grid()函数并将其移动到下一行代码。一个赋值,例如: from Tkinter import * window = Tk() window.config(background="green") window.bind("<Escape>", quit) cbttn = Checkbutton(text="Caps?").grid(row=3, column=0) cbttn中的收益属于非类型对象 删除对cbttn的分配(如果不
是否适用?或者我必须移动.grid()
函数并将其移动到下一行代码。一个赋值,例如:
from Tkinter import *
window = Tk()
window.config(background="green")
window.bind("<Escape>", quit)
cbttn = Checkbutton(text="Caps?").grid(row=3, column=0)
cbttn中的收益属于非类型对象
删除对cbttn的分配(如果不想在脚本中进一步引用)
或将栅格移动到新行,如下所示:
Checkbutton(text="Caps?").grid(row=3, column=0)
要查看是否按下了检查按钮,请使用可用的命令选项。检查示例。举个例子:
cbttn = Checkbutton(text="Caps?")
cbttn.grid(row=3, column=0)
输出应保持在0和1之间切换,但如何确定是否已单击它,是否要在if,elif命令中使用它?@PeterGalibaYear7我编辑了答案。对于复选按钮,不需要使用if..elif..else。希望这能澄清这一点现在回溯(最近一次调用最后一次):File“/data/data/ru.iiec.pydroid3/files/coding folder/alphabet\u draw0.1.0.py”,第39行,text=Label(text=cbttn.variable)AttributeError:“Checkbutton”对象没有属性“variable”
cbttn = Checkbutton(text="Caps?")
cbttn.grid(row=3, column=0)
from tkinter import *
def display():
print(CheckVar1.get())
top = Tk()
CheckVar1 = IntVar()
CheckVar2 = IntVar()
C1 = Checkbutton(top, text = "Music", variable = CheckVar1, \
onvalue = 1, offvalue = 0, height=5, \
width = 20, command = display)
C2 = Checkbutton(top, text = "Video", variable = CheckVar2, \
onvalue = 1, offvalue = 0, height=5, \
width = 20)
C1.pack()
C2.pack()
top.mainloop()