ฉันจะรับสถานะของ Checkbutton
ใน python ได้อย่างไร ฉันมีสิ่งนี้:
def doSomething():
if #code goes here, if checkbutton is selected
...
check = Checkbutton(window, text="Add both", onvalue = 1, offvalue = 0)
check.pack(side="right")
ฉันจะรับสถานะของ Checkbutton
ใน python ได้อย่างไร ฉันมีสิ่งนี้:
def doSomething():
if #code goes here, if checkbutton is selected
...
check = Checkbutton(window, text="Add both", onvalue = 1, offvalue = 0)
check.pack(side="right")
คุณต้องเชื่อมโยง Checkbox
กับตัวแปร:
is_checked = IntVar()
check = Checkbutton(window, text="Add both", onvalue=1, offvalue=0, variable=is_checked)
จากนั้นใช้ทำการตรวจสอบของคุณเช่น:
if is_checked.get():
# do something
.get()
- person ArtOfWarfare; 29.09.2014