December 2017
Beginner
412 pages
10h 8m
English
Labels are widgets that are used to display short pieces of text. Here we create a Label that belongs to the root window—its parent widget—and we specify the text to be displayed by assigning it to the Label’s text parameter.
| | import tkinter |
| | |
| | window = tkinter.Tk() |
| | label = tkinter.Label(window, text='This is our label.') |
| | label.pack() |
| | |
| | window.mainloop() |
Here is the resulting GUI:

Method call label.pack() is crucial. Each widget has a method called pack that places it in its parent widget and then tells the parent to resize itself as necessary. If we forget to call this method, the child widget (in this case,
Read now
Unlock full access