Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tkinter 如何使Checkbutton的变量工作并在屏幕上显示一些按钮?_Tkinter_Pydroid - Fatal编程技术网

Tkinter 如何使Checkbutton的变量工作并在屏幕上显示一些按钮?

Tkinter 如何使Checkbutton的变量工作并在屏幕上显示一些按钮?,tkinter,pydroid,Tkinter,Pydroid,我想了解如何根据CheckVar1的值来显示不同的按钮。 我没有错误,但是我想使用的代码是if-CheckVar1==0:和if-CheckVar1==1。在IntVar上使用跟踪方法 你也可以让按钮只做一次吗?只要把你的按钮放在一个框架中,并在需要时显示相应的框架。 from Tkinter import * window = Tk() CheckVar1 = IntVar() cbttn = Checkbutton(text="Caps?", variable = CheckVar1, \

我想了解如何根据CheckVar1的值来显示不同的按钮。 我没有错误,但是我想使用的代码是if-CheckVar1==0:和if-CheckVar1==1。

在IntVar上使用跟踪方法


你也可以让按钮只做一次吗?只要把你的按钮放在一个框架中,并在需要时显示相应的框架。
from Tkinter import *
window = Tk()
CheckVar1 = IntVar()
cbttn = Checkbutton(text="Caps?", variable = CheckVar1, \
onvalue = 1, offvalue = 0, height=5, \
width = 20)
cbttn.grid(row=3, column=0)
while True:
    if CheckVar1 == 0:
        a = Button(text="a").grid(column=1)
        b = Button(text="b").grid(column=1)
        c = Button(text="c").grid(column=1)
        d = Button(text="d").grid(column=1)
        e = Button(text="e").grid(column=1)
        f = Button(text="f").grid(column=1)
        g = Button(text="g").grid(column=1)
    if CheckVar1 == 1:
        A = Button(text="A").grid(column=1)
    window.mainloop()#makes everything work
from Tkinter import *
window = Tk()
CheckVar1 = IntVar()
cbttn = Checkbutton(text="Caps?", variable = CheckVar1, onvalue = 1, offvalue = 0, height=5,width = 20)
cbttn.grid(row=3, column=0)

def trace_method(*args):
    print ("Changed")
    if CheckVar1.get() == 0: #note that you need to call `get` method on the IntVar
        a = Button(text="a").grid(column=1)
        b = Button(text="b").grid(column=1)
        c = Button(text="c").grid(column=1)
        d = Button(text="d").grid(column=1)
        e = Button(text="e").grid(column=1)
        f = Button(text="f").grid(column=1)
        g = Button(text="g").grid(column=1)
    elif CheckVar1.get() == 1:
        A = Button(text="A").grid(column=1)

CheckVar1.trace("w",trace_method)

window.mainloop()