April 2018
Beginner
340 pages
7h 54m
English
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) ...