小编Coe*_*ser的帖子

tkinter 复选按钮未设置变量

无论我对我的复选按钮做什么,它似乎都没有设置变量。以下是所涉及的代码部分:

class Window:
    def __init__(self):
        self.manualb = 0 #to set the default value to 0

    def setscreen(self):
        #screen and other buttons and stuff set here but thats all working fine
        manual = tkr.Checkbutton(master=self.root, variable=self.manualb, command=self.setMan, onvalue=0, offvalue=1) #tried with and without onvalue/offvalue, made no difference
        manual.grid(row=1, column=6)

    def setMan(self):
        print(self.manualb)
        #does some other unrelated stuff
Run Code Online (Sandbox Code Playgroud)

它只是一直打印 0。我做错了什么吗?没有其他任何东西可以手动操作。

python tkinter

-1
推荐指数
1
解决办法
2090
查看次数

标签 统计

python ×1

tkinter ×1