Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

4.3 Advanced GUI Widgets

Lesson 27 of 32 in the free Data Visualisation and Analytics notes on Siksha Sarovar, written by Rohit Jangra.

Advanced Tkinter: Selection, Menus, and Dialogs

1. Tkinter Variable Types

Tkinter uses special variable classes to track widget state. They automatically update the GUI when changed.

Variable TypeData StoredCommon Use
StringVar()Text stringEntry fields, Radiobutton with text values
IntVar()IntegerCheckbuttons (0/1), Radiobutton with numeric values
DoubleVar()FloatScale/slider widgets, calculations
BooleanVar()True/FalseToggle switches

Key Methods: .get() retrieves the value, .set(value) updates it.

2. Selection Widgets

For user choices, pair widgets with Tkinter Variables to track state.

WidgetDescriptionCode SnippetState Tracking
CheckbuttonBinary choice (On/Off). Multiple selectable.tk.Checkbutton(root, text="Remember", variable=var)IntVar (0 or 1)
RadiobuttonExclusive choice (One of Many)tk.Radiobutton(root, text="Male", variable=v, value="M")StringVar / IntVar
ListboxList of items to selectlb = tk.Listbox(root); lb.insert(1, "Option").curselection() method
SpinboxNumeric input with up/down arrowstk.Spinbox(root, from_=0, to=100)StringVar
ScaleHorizontal/vertical slidertk.Scale(root, from_=0, to=100, orient="horizontal")IntVar / DoubleVar
ComboboxDropdown selection (ttk)ttk.Combobox(root, values=["A","B","C"])StringVar

3. Menus

Creating a standard top-bar menu (File, Edit, Help).

Steps:

  1. Create the MenuBar (container).
  2. Create a Menu (e.g., "File") and add commands (add_command).
  3. Cascade the File menu into the MenuBar.
  4. Configure the root to use this menu.
menubar = tk.Menu(root)
file_menu = tk.Menu(menubar, tearoff=0)
file_menu.add_command(label="New", command=new_file)
file_menu.add_command(label="Open", command=open_file)
file_menu.add_separator()
file_menu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="File", menu=file_menu)

root.config(menu=menubar)

4. Dialog Boxes

Pop-up windows for user feedback. Import: from tkinter import messagebox, filedialog.

Message Dialogs:

FunctionIconUsageReturns
showinfo(title, msg)(i)General informationNone
showwarning(title, msg)(!)Alert user to cautionNone
showerror(title, msg)(X)Critical failureNone
askyesno(title, msg)(?)Yes/No confirmationTrue / False
askokcancel(title, msg)(?)OK/Cancel confirmationTrue / False

File Dialogs:

FunctionPurposeReturns
filedialog.askopenfilename()Open file pickerFile path string
filedialog.asksaveasfilename()Save file pickerFile path string
filedialog.askdirectory()Select folderDirectory path string