How to collect multiple options from user in Tkinter GUI application : Checkbutton Widget


Checkbutton Widget

Gives user to select multiple options, as in above image
  • can display text as an option
  • can display image as well in place of text
Syntax:

            Checkbutton(master, options.........)

master : master is nothing but the window object (parent window for which Checkbutton needs to be created )

options : options are used to shape the entry separated by comma's and to define action on click. Below is the list of options, can be passed while creating Checkbutton.

  • activebackground
  • activeforeground
  • bg
  • bitmap
  • bd
  • command
  • cursor
  • disabledforeground
  • font
  • fg
  • height
  • highlightcolor
  • image
  • justify
  • offvalue
  • onvalue
  • padx
  • pady
  • relief
  • selectcolor
  • selectimage
  • state
  • text
  • underline
  • variable
  • width
  • wraplength

Checkbutton built in Methods
  • deselect()
    • Clears the checkbutton.
  • flash()
    • Flashes the checkbutton a few times between its active and normal colors, but leaves it the way it started.
  • invoke()
    • To get the same actions that would occur if the user clicked on the checkbutton to change its state.
  • select()
    • Sets the checkbutton.
  • toggle()
    • Clears the checkbutton if set, sets if its already cleared


there are few options which may not work on mac, but work finely on windows and linux

Example for the Checkbutton widget, output screen shot is on top of this post



# program to create checkbutton widget

try:
from Tkinter import *
except:
from tkinter import *

mw = Tk()
mw.geometry(
'400x100+10+10')
mw.title(
"AETies : Automation Expert Technologies")

label = Label(mw
, text='Select your subject')
label.grid(
row=1, column=1)

ch_btn1 = Checkbutton(mw
, text="Python", onvalue=1, offvalue=0)
ch_btn1.grid(
row=2, column=2)

ch_btn2 = Checkbutton(mw
, text="Embedded", onvalue=1, offvalue=0)
ch_btn2.grid(
row=2, column=3)

ch_btn3 = Checkbutton(mw
, text="Language C", onvalue=1, offvalue=0)
ch_btn3.grid(
row=2, column=4)

mw.mainloop()





Comments

My photo
Techno Xpresss
Bangalore, Karnataka, India