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

Saving the user's choices

To ensure the user is able to save their choices, we need a Save button:

self.save_button = ttk.Button(self, text="Save", command=self.save)

Now we can finish off our __init__ method by packing all of our widgets:

self.save_button.pack(side=tk.BOTTOM, fill=tk.X, expand=1, padx=40)self.font_list.pack(side=tk.LEFT, fill=tk.Y, expand=1)self.size_input.pack(side=tk.BOTTOM, fill=tk.X, expand=1)

Since our Save button calls a method called save, let's define this now.

def save(self):    font_family = self.font_list.get(self.font_list.curselection()[0])    font_size = self.size_input.get()    yaml_file_contents = f"family: {font_family}\n" \                           + f"size: {font_size}"    with open('schemes/font.yaml', 'w') as file: file.write(yaml_file_contents) ...
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