Widgets – the building blocks of GUI programs

Now that we have our top level or the root window ready, it is time to think over a question—which components should appear in the window? In Tkinter jargon, these components are called widgets.

The syntax that is used to add a widget is as follows:

my_widget = Widget-name (its container window, ** its configuration options)

In the following example (1.02.py), we will add two widgets, a label, and a button to the root frame. Note how all the widgets are added between the skeleton code that we defined in the first example:

from tkinter import *
root = Tk()
label = Label(root, text="I am a label widget")
button = Button(root, text="I am a button")
label.pack()
button.pack()
root.mainloop()

The following is ...

Get Tkinter GUI Application Development Blueprints now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.