Creating a Tkinter Hello World

Let's learn the basics of Tkinter by creating a simple Hello World script for Tkinter by performing the following steps:

  1. Create a new file in IDLE or your favorite editor, enter the following code, and save it as hello_tkinter.py:
"""Hello World application for Tkinter"""

from tkinter import *
from tkinter.ttk import *

root = Tk()
label = Label(root, text="Hello World")
label.pack()
root.mainloop()
  1. Run this in IDLE by hitting F5 or in your terminal by typing the following command:
python3 hello_tkinter.py

You should see a very tiny window pop up with the text Hello World as shown in the following screenshot:

  1. Close the window and return to your editor screen. Let's break down this code and talk about what ...

Get Python GUI Programming with Tkinter now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.