100% found this document useful (1 vote)
889 views1 page

Tkinter CheatSheet

Uploaded by

Amandeep
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
100% found this document useful (1 vote)
889 views1 page

Tkinter CheatSheet

Uploaded by

Amandeep
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

Position Widgets using pack(), place() or grid()

The most popular GUI creation tool for


Tkinter Python, Tkinter provides a number of pack() organizes widgets in horizontal and vertical boxes that are limited to left, right, top, bottom

Cheat Sheet widgets and methods you can use to


create a user interface for your application.
positions. Each box is offset and relative to each other.

root.geometry(‘200x100’)
test = tk.Label(root, text=”pack(side=tk.bottom)”, bg=”teal”)
Tkinter Widgets test.pack(side=tk.bottom)

from tkinter import * Options:


Code from tkinter import *
from tkinter.ttk import * padx pads externally along the x axis
Button pady pads externally along the y axis
Combobox
instance = Button(root, text="Click instance = ttk.Combobox(master, ipadx pads internally along the x axis
me!", ...) pack(side=tk.bottom) ipady pads internally along the y axis
option=value, ...)
Widgets Checkbutton Notebook
instance = tk.Checkbutton(parent, instance = place() places widgets in a two grid() locates widgets in a two
option, ... ) ttk.Notebook(container, options, dimensional grid using x and y absolute dimensional grid using row and column
Entry
... ) coordinates. absolute coordinates.
instance = tk.Entry(master, option, Progressbar
...) instance = Progressbar(parent, root.geometry(‘200x100’) root.geometry(‘200x100’)
options, ... ) Label(root, text=”place(x=5, y=2)”, Label(root, text=”grid(row=2, column=2)”,
Frame
instance = Frame(parent, option, ...) Separator bg=”#A3DBE0”).place(x=5, y=2) width=12).grid(row=2, column=2)
# orient options are
Label 'horizontal' or 'vertical': 5
instance = tk.Label(text="some text") instance = 4
ttk.Separator(container,orient=' 3
LabelFrame horizontal')
instance = LabelFrame( master, option, 2 place(x=5,y=2) grid(row=2,column=2)

... ) Sizegrip 1
instance = ttk.Sizegrip(master,
Menubutton options, ... ) 1 2 3 4 5 6 7 8
instance = Menubutton ( master,
options, ... ) Treeview
instance = ttk.Treeview(master,
Tkinter Images with Pillow
PanedWindow options, ... ) # Pillow is imported as PIL
instance = PanedWindow(master, from PIL import ImageTk, Image
options, ... )
image1 = Image.open("<path/image_name>")
Radiobutton test = ImageTk.PhotoImage(image1)
instance = Radiobutton(master,
options, ... ) label1 = tkinter.Label(image=test)
label1.image = test
Scale
instance = Scale (master, option, ... # Position image as the background image
) label1.place(x=1, y=1)
# Resize image to fit on button
Scrollbar photoimage = photo.subsample(1, 2)
instance = Scrollbar ( master, # Position image on button
options, ... ) Button(root, image = photoimage,).pack(side = BOTTOM)

©2021 ActiveState Software Inc. All rights reserved. ActiveState®,


ActivePerl®, ActiveTcl®, ActivePython®, Komodo®, ActiveGo™, ActiveRuby™,
For more Python packages related resources visit activestate.com/learn-python ActiveNode™, ActiveLua™, and The Open Source Languages Company™ are
all trademarks of Activestate.

You might also like