Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Labels
Description
Problem
NavigationToolbar2Tk uses standard Tk buttons which can be a bit janky looking, especially if you're using ttk elements elsewhere in your GUI. Having an option to use ttk elements in the toolbar would make for a more consistent look throughout such an application.
Proposed solution
I've found this to work pretty well, although I've only tested it in the most basic case. Not sure about DPI rescaling, etc.
class NavigationToolbar2Ttk(NavigationToolbar2Tk): def _Button(self, text, image_file, toggle, command): im = tk.PhotoImage(master=self, file=image_file) b = ttk.Button(self, text=text, padding=(2, 2), image=im, command=command) b._ntimage = im b.pack(side='left') return b def _Spacer(self): s = ttk.Separator(master=self, orient='vertical') s.pack(side='left', padx='3p', pady='5p', fill='y') return s def _update_buttons_checked(self): for text in ['Zoom', 'Pan']: if text in self._buttons: if self.mode.name == text.upper(): self._buttons[text].state(['pressed']) else: self._buttons[text].state(['!pressed'])