33% found this document useful (3 votes)
11K views1 page

Tkinter Cheat Sheet

This document provides a cheat sheet on Python Tkinter widgets. It lists common widgets like labels, buttons, menus, entries and checkboxes along with their purposes. It also covers creating a treeview, cascading menus, file dialogs and popups. Widget properties like background, text and command are described. The cheat sheet is a reference for importing and using Tkinter widgets in Python applications.

Uploaded by

jhdmss
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
33% found this document useful (3 votes)
11K views1 page

Tkinter Cheat Sheet

This document provides a cheat sheet on Python Tkinter widgets. It lists common widgets like labels, buttons, menus, entries and checkboxes along with their purposes. It also covers creating a treeview, cascading menus, file dialogs and popups. Widget properties like background, text and command are described. The cheat sheet is a reference for importing and using Tkinter widgets in Python applications.

Uploaded by

jhdmss
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Python Tkinter – Cheat Sheet Widget (information) Purpose Create Treeview

Basic Level
https://engmrk.com Tk.Label, ttk.Label Display static text or image >>> treeview = ttk.Treeview ( root )
Tk.Message Display static multi line text
>>> treeview.pack ( )
>>> treeview.insert ( ‘ ‘, ‘item1’, text = ‘First item’)
The most commonly used GUI programming toolkit for Ttk.Separator Display a horizontal or vertical separator bar >>> treeview.insert ( ‘ ‘, ‘item2’, text = ‘Second item’)
Python. Ttk.Progressbar Show status of running operation
>>> treeview.cofig (height = 5, column = (‘Version’))
>>> treeview.column (‘Version’, width = 50, anchor = CENTER)
How to import? Ttk.Treeview Display hierarchical collection of items
>>> import tkinter or from tkinter import *
Create Cascading Menu
Widget (Grouping) Purpose
Application Main Window >>> root.option_add (‘*tearoff’, False)
Tk.Frame, ttk.Frame Displays set of widgets as one unit
>>> menubar = Menu (root)
How to instantiate main window of application? Ttk.LabelFrame Frame but with border and title >>> root.config (menu = menubar)
>>> root = Tk ( ) Tk.PanedWindow Group widgets in re-sizable panes
>>> file = Menu (menubar)
>>> edit= Menu (menubar)
Ttk.Notebook Tabbed set of frames, only one visible at a time >>> help_ = Menu (menubar)
Widgets >>> menubar.add_cascade (menu = file, label = ‘File’)
Import ‘generic’ widgets: >>> import tkinter Common Properties: >>> menubar.add_cascade (menu = edit, label = ‘Edit’)
background, foreground, width, height, borderwidth, text, >>> menubar.add_cascade (menu = help_, label = ‘Help’)
Import ‘styled’ widgets: >>> from tkinter import ttk >>> file.add_command (label = ‘New’, command = lambda: print(‘New
font, cursor, activeforeground, activebackground, image.
File’)
Widget (Interactive) Purpose Specific Properties: >>> file.add_separator ()
Ttk.Button, tk.Button Execute a command, function or task 1- Scale: from_ , to. orient, resolution. >>> file.entryconfig ( ‘New’, accelerator = ‘Ctrl + N’)

Tk.Menu Implements Top-level, pull-down and popup menus


2- Radiobutton: variable, value.
3- Spinbox: from_ , to, textvariable. File Dialog
Ttk.Menubutton Display popup or pull-down menu when activated
4-Button: command. >>> from tkinter import filedialog
Tk.OptionMenu Creates a popup menu, and a button to display 5- Checkbutton: onvalue, offvalue, variable. >>> filename = filedialog.askopenfile ( )
Tk.Entry, ttk.Entry Text entry (one line only) 6- Combobox: textvariable, values.
7- Progressbar: orient, mode, step. Color Chooser
Tk.Text Text entry (multiple lines)
8- Text: wrap, xscrollcommand, yscrollcommand. >>> from tkinter import colorchooser
Tk.Checkbutton, On-Off, True-False selection
ttk.Checkbutton
9- Scrollbar: orient, command. >>> colorchooser.askcolor ( initialcolor = ‘#FFFFFF’ )

Tk.Radiobutton, One or Multiple selections


Create Widgets Popup Message
ttk.Radiobutton
>>> from tkinter import messagebox
Tk.Listbox Selection from a list of alternatives >>> widget_name= ttk.Label ( root, text = ‘Example Text’ ) >>> messagebox.showinfo( title = ‘Example’, message = ‘some text’ )
Ttk.Combobox Combined text field with a pop-down list

Tk.Scale, ttk.Scale Moving slider for selecting numerical values


Set Widget Properties
Prepared by: Eng. Muhammad Rizwan Khan
Note: Widgets with tk are generic whereas ttk are styled. >>> widget_name.config ( text = ‘Example Text’ ) Reference: https://docs.python.org/3/library/tkinter.ttk.html

You might also like