18.3. Tkinter Examples

18.3.1. Label Widget

In Example 18.1, we present tkhello1.py, the Tkinter version of “Hello World!” In particular, it shows you how a Tkinter application is set up and highlights the Label widget

Listing 18.1. Label Widget Demo (tkhello1.py)

Our first Tkinter example is… what else? “Hello World!” In particular, we introduce our first widget, the Label.

1  #!/usr/bin/env python
2  
3  import Tkinter
4
5  top = Tkinter.Tk()
6  label = Tkinter.Label(top, text='Hello World!')
7  label.pack()
8  Tkinter.mainloop()

In the first line, we create our top-level window. That is followed by our Label widget containing the all-too-famous string. We instruct the packer to manage and display our widget, and finally call mainloop() to run ...

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