article

Wednesday, July 3, 2019

Python GUI Tkinter Checkbutton Tutorial

Python GUI Tkinter Checkbutton Tutorial
 
from Tkinter import *
master = Tk()
master.geometry('250x200')

def var_states():
    print("Male : %d, \nFemale : %d" % (var1.get(), var2.get()))
def callbackFunc():
    if (chkValue.get()):
       tlabel = Label(master, text="Oh. I'm click value is {}".format(chkValue.get()))
       tlabel.pack()
    else:
       tlabel = Label(master, text="Oh. I'm Not clicked")
       tlabel.pack()
Label(master, text="Your sex:").grid(row=0, sticky=W)
var1 = IntVar()
Checkbutton(master, text="Male", variable=var1).grid(row=1, sticky=W)
var2 = IntVar()
Checkbutton(master, text="Female", variable=var2).grid(row=2, sticky=W)
Button(master, text="Quit", command=master.quit).grid(row=3, sticky=W, pady=4)
Button(master, text='Show', command=var_states).grid(row=4, sticky=W, pady=4)

chkValue = BooleanVar()
chkExample = Checkbutton(master, text="Check box", var=chkValue,command=callbackFunc)
chkExample.grid(column=10,row=10)
mainloop()

Related Post