4

CheckbuttonPythonでaの状態を取得するにはどうすればよいですか? 私はこれを持っています:

def doSomething():

  if #code goes here, if checkbutton is selected
   ...

check = Checkbutton(window, text="Add both", onvalue = 1, offvalue = 0)
check.pack(side="right")
4

1 に答える 1

7

Checkboxを変数に関連付ける必要があります。

is_checked = IntVar()
check = Checkbutton(window, text="Add both", onvalue=1, offvalue=0, variable=is_checked)

次に、次のようなチェックを行います。

if is_checked.get():
    # do something
于 2013-05-27T18:15:59.537 に答える