0

I create Checkbutton

var = IntVar()
cb = Checkbutton(master, variable=var)

I can set and read status checkbutton with variable

var.set(1)
var.get()

I can set the status of a checkbutton via the checkbutton itself

cb.select()
cb.deselect()

How can I read the status of a checkbutton through a variable cb without variable var?

4

1 回答 1

1

您必须使用 Tkinter 变量来查询 Checkbutton 的状态。这也是一种非常常见的模式,因此您不必担心用于定义 IntVar 的额外代码行。它也有它的优点,比如可以在变量的值发生变化时进行跟踪。

于 2013-06-23T11:08:02.470 回答