Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Home » Python » Tkinter » Checkbutton

Python Tkinter Examples


from tkinter import *
from PIL import ImageTk, Image

root = Tk()
root.title('Example of Checkbutton in Python Tkinter')
#root.iconbitmap('c:/img/icon.ico')
root.geometry("400x300")

def func():
    label = Label(root, text=var.get()).pack()
var = IntVar()

checkbox = Checkbutton(root, text="My Checkbutton", variable = var)
checkbox.pack()

button = Button(root, text="Show Value of Checkbutton", command=func)
button.pack()

root.mainloop()
how to display checkbutton in Python Tkinter

Setting onvalue & offvalue of checkbutton


from tkinter import *
from PIL import ImageTk, Image

root = Tk()
root.title('Example of Checkbutton in Python Tkinter')
#root.iconbitmap('c:/img/icon.ico')
root.geometry("400x300")

var = StringVar()

def func():
    label = Label(root, text=var.get()).pack()

checkbox = Checkbutton(root, text="My Checkbutton", variable = var, onvalue="Selected", offvalue="Not Selected")
checkbox.pack()

button = Button(root, text="Show Value of Checkbutton", command=func)
button.pack()

root.mainloop()