Skip to Content
Tkinter GUI Programming by Example
book

Tkinter GUI Programming by Example

by David Love
April 2018
Beginner content levelBeginner
340 pages
7h 54m
English
Packt Publishing
Content preview from Tkinter GUI Programming by Example

Adding interactivity

Of course, without any interactivity, this is just a message box. Let's add something for the user to do with our application. Bring the source code back up and change the __init__ method to look like this:

class Window(tk.Tk):  def __init__(self):    super().__init__()    self.title("Hello Tkinter")    self.label = tk.Label(self, text="Choose One")    self.label.pack(fill=tk.BOTH, expand=1, padx=100, pady=30)    hello_button = tk.Button(self, text="Say Hello",                              command=self.say_hello)    hello_button.pack(side=tk.LEFT, padx=(20, 0), pady=(0, 20))    goodbye_button = tk.Button(self, text="Say Goodbye",                               command=self.say_goodbye)    goodbye_button.pack(side=tk.RIGHT, padx=(0, 20), pady=(0, 20))

Our label has changed to say Choose one to indicate ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Tkinter GUI Application Development Blueprints, Second Edition - Second Edition

Tkinter GUI Application Development Blueprints, Second Edition - Second Edition

Bhaskar Chaudhary

Publisher Resources

ISBN: 9781788627481Supplemental Content