O'Reilly logo

Tkinter GUI Programming by Example by David Love

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Fixing our application

Let's get our Hello World application working as intended again using our new knowledge of Tkinter variables. After setting the title, change the label_text property as follows:

self.label_text = tk.StringVar()self.label_text.set("Choose One")

Now, alter our other two methods like so:

def say_hello(self):    self.label_text.set("Hello World")def say_goodbye(self):    self.label_text.set("Goodbye! \n (Closing in 2 seconds)")    self.after(2000, self.destroy)

Once again, run the application and click both buttons. Everything should now be all working as before.

Great! We now know how to take advantage of Tkinter's special variables, and it's super easy.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required