App 5: Desktop App with Windows & Buttons / Build a calculator
Lesson 1 of 10
Your first window
Tkinter comes with Python and makes windows with buttons, text boxes and more. Every Tkinter app creates a window and then runs mainloop(), which waits for clicks.
Key points
- import tkinter as tk
- root = tk.Tk() makes the window
- root.mainloop() keeps it open
import tkinter as tk
root = tk.Tk()
root.title("My first app")
root.geometry("320x200")
tk.Label(root, text="Hello from Tkinter!", font=("Arial", 16)).pack(pady=40)
root.mainloop()Your turn
Run the example. On Ubuntu, install Tkinter first with: sudo apt install python3-tk
Quiz · +10 XP
What does root.mainloop() do?
Log in to save progress and earn XP.