Adding a label to the GUI form

Getting ready

We are extending the first recipe. We will leave the GUI resizable, so don't use the code from the second recipe (or comment the win.resizable line 4 out).

How to do it...

In order to add a Label widget to our GUI, we are importing the ttk module from tkinter. Please note the two import statements.

# imports                  # 1
import tkinter as tk       # 2
from tkinter import ttk    # 3

Add the following code just above win.mainloop() located at the bottom of recipes 1 and 2.

# Adding a Label           # 4
ttk.Label(win, text="A Label").grid(column=0, row=0) # 5

Running the code adds a label to our GUI:

How to do it...

How it works...

In line 3 of the above ...

Get Python GUI Programming Cookbook 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.