From c151396e4ef2b6a38e1aab6cdadd13365eb552c3 Mon Sep 17 00:00:00 2001 From: Jonathan Harris Date: Mon, 1 Feb 2016 02:06:22 +0000 Subject: [PATCH] Add ColoredButton for colored backgrounds --- myNotebook.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/myNotebook.py b/myNotebook.py index 65d4595d..cf2e6983 100644 --- a/myNotebook.py +++ b/myNotebook.py @@ -90,6 +90,22 @@ class Button(platform == 'darwin' and tk.Button or ttk.Button): else: ttk.Button.__init__(self, master, **kw) +class ColoredButton(platform == 'darwin' and tk.Label or tk.Button): + + def __init__(self, master=None, **kw): + if platform == 'darwin': + # Can't set Button background on OSX, so use a Label instead + kw['relief'] = kw.pop('relief', tk.RAISED) + self._command = kw.pop('command', None) + tk.Label.__init__(self, master, **kw) + self.bind('', self._press) + else: + tk.Button.__init__(self, master, **kw) + + if platform == 'darwin': + def _press(self, event): + self._command() + class Checkbutton(platform == 'darwin' and tk.Checkbutton or ttk.Checkbutton): def __init__(self, master=None, **kw):