🪟 GUI Cheatsheet

Build windows with buttons and boxes using guizero. Copy any example into the Editor and press ▶ Run.

🚀 Getting started

Make an App (the window), add some widgets, then call app.display() to show it.

from guizero import App, Text, PushButton

def on_click():
    label.value = "You clicked me! 🎉"

app = App(title="My first window")

label = Text(app, text="Press the button")
PushButton(app, text="Click me", command=on_click)

app.display()

The first argument to every widget is its master — the container it goes in. For now that is always app (or a Box, see below).

💡 command=on_click gives the button a function to run when it is pressed. Write the function name without brackets.

🧱 The widgets

The building blocks you can add to a window.

Text(app, text=...)A label that shows some words.
PushButton(app, text=..., command=...)A button that runs a function when clicked.
TextBox(app, text=...)A box the user can type into.
CheckBox(app, text=...)A tick box that is on or off.
ButtonGroup(app, options=[...])Radio buttons: pick one option.
Combo(app, options=[...])A drop-down list: pick one option.
Slider(app, start=..., end=...)A slider for choosing a number.
Box(app)A container to group other widgets.

💬 Reading & changing widgets

Every widget has a .value you can read or set.

label.valueGet or set the text shown by a Text.
box.valueThe text typed into a TextBox.
check.value1 if ticked, 0 if not.
group.valueThe value of the chosen radio button.
combo.valueThe chosen drop-down option.
slider.valueThe slider's current number.
from guizero import App, TextBox, PushButton, Text

def greet():
    hello.value = "Hello " + name.value + "! 👋"

app = App(title="Greeter")

name = TextBox(app, text="")
PushButton(app, text="Greet me", command=greet)
hello = Text(app, text="")

app.display()

🔘 Choices: checkbox, radio & drop-down

Let the user pick things. ButtonGroup is a set of radio buttons; Combo is a drop-down.

from guizero import App, CheckBox, ButtonGroup, Combo, PushButton, Text

def show():
    parts = []
    if sprinkles.value:
        parts.append("sprinkles")
    parts.append(flavour.value)
    parts.append(size.value)
    result.value = " ".join(parts)

app = App(title="Ice cream")

sprinkles = CheckBox(app, text="Add sprinkles")
flavour = ButtonGroup(app, options=["vanilla", "chocolate", "mint"], selected="vanilla")
size = Combo(app, options=["small", "medium", "large"])
PushButton(app, text="Order", command=show)
result = Text(app, text="")

app.display()
💡 ButtonGroup can use hidden values with a 2D list: options=[["Cheese", "c"], ["Ham", "h"]] — the first word shows, the second is the value.

🎚️ Sliders & live events

A widget's command runs whenever it changes — great for live updates. A Slider passes its new value to the function.

from guizero import App, Slider, Text

def update(value):
    label.value = "Volume: " + value

app = App(title="Volume")
label = Text(app, text="Volume: 0")
Slider(app, start=0, end=11, command=update)
app.display()

📐 Laying out widgets

By default widgets stack in a centred column (auto layout). For neat rows and columns, use layout="grid" and give each widget a grid=[x, y] position.

App(..., layout="grid")Turn on grid layout for the window.
grid=[x, y]Column x, row y (both start at 0).
grid=[x, y, xspan, yspan]Also span across columns/rows.
align="left"Stick a widget to a side: left, right, top or bottom.
from guizero import App, Text, TextBox

app = App(title="Form", layout="grid")

Text(app, text="Name", grid=[0, 0], align="left")
TextBox(app, grid=[1, 0])
Text(app, text="Age", grid=[0, 1], align="left")
TextBox(app, grid=[1, 1])

app.display()
💡 In guizero the grid is [x, y] — that is column first, then row.

📦 Grouping with Box

A Box is a container you put inside the app. Widgets added to the box group together, which helps you arrange bigger windows.

from guizero import App, Box, Text, PushButton

app = App(title="Boxes")

top = Box(app, border=True)
Text(top, text="I am in the top box")

bottom = Box(app, border=True)
PushButton(bottom, text="Button in the bottom box")

app.display()

🧩 Passing extra information (args)

Use args to send extra values to a command, so one function can serve several buttons.

from guizero import App, PushButton, Text

def pick(fruit):
    chosen.value = "You picked " + fruit

app = App(title="Fruit", layout="grid")

PushButton(app, text="Apple",  command=pick, args=["apple"],  grid=[0, 0])
PushButton(app, text="Banana", command=pick, args=["banana"], grid=[1, 0])
chosen = Text(app, text="", grid=[0, 1, 2, 1])

app.display()

📦 The real guizero & limits of this version

In this editor, guizero is a small stand-in that draws the window using the web page itself, so there is nothing to install here. The examples above use the same commands as the real library, so your code should run elsewhere too.

Using it outside this editor. On a normal computer (for example in Thonny or IDLE), install the official library first:

pip install guizero

The official project lives at pypi.org/project/guizero with docs and a full widget guide at lawsie.github.io/guizero. It is built on Python's standard tkinter and opens a real desktop window.

What this editor's version does not do. It only copies the most common widgets and options, so a few things from the real library are missing:

display() does not blockIn the real library app.display() waits until you close the window. Here it shows the window and your program keeps going; button commands still work afterwards.
Fewer widgetsOnly App, Box, Text, PushButton, TextBox, CheckBox, ButtonGroup, Combo and Slider are supported. Others like ListBox, Picture, Waffle, Drawing, Window and MenuBar are not.
command= onlyEvent handling is through the command parameter (with args). Low-level bind(...) for key presses and mouse events is not available here.
No schedulingafter(...), repeat(...) and cancel(...) timers are not implemented.
Simpler stylingColours, fonts and sizes follow the page theme. Properties like bg, text_color and font are accepted in code but may not change how things look here.
Looks differentWidgets are drawn with the web page, so they will not look exactly like the desktop window you get in Thonny — but they behave the same.
💡 Stick to the widgets and .value / command= shown above and your program will behave the same here and with the official library.