Skip to content

Commit

Permalink
[2186] Additional Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Rixxan committed Apr 5, 2024
1 parent 3a8227a commit e0ef9b5
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions myNotebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ def __init__(self, master: ttk.Frame | None = None, **kw):

super().__init__(master, **kw)
style = ttk.Style()
style.configure('nb.TFrame', background=PAGEBG)
style.configure('nb.TButton', background=PAGEBG)
style.configure('nb.TCheckbutton', foreground=PAGEFG, background=PAGEBG)
style.configure('nb.TMenubutton', foreground=PAGEFG, background=PAGEBG)
style.configure('nb.TRadiobutton', foreground=PAGEFG, background=PAGEBG)
if sys.platform == 'win32':
style.configure('nb.TFrame', background=PAGEBG)
style.configure('nb.TButton', background=PAGEBG)
style.configure('nb.TCheckbutton', foreground=PAGEFG, background=PAGEBG)
style.configure('nb.TMenubutton', foreground=PAGEFG, background=PAGEBG)
style.configure('nb.TRadiobutton', foreground=PAGEFG, background=PAGEBG)
self.grid(padx=10, pady=10, sticky=tk.NSEW)


class Frame(tk.Frame or ttk.Frame): # type: ignore
class Frame(ttk.Frame):
"""Custom t(t)k.Frame class to fix some display issues."""

def __init__(self, master: ttk.Notebook | None = None, **kw):
Expand Down Expand Up @@ -127,7 +128,7 @@ def __init__(self, master: ttk.Frame | None = None, **kw):
EntryMenu.__init__(self, master, **kw)


class Button(tk.Button or ttk.Button): # type: ignore
class Button(ttk.Button): # type: ignore
"""Custom t(t)k.Button class to fix some display issues."""

# DEPRECATED: Migrate to ttk.Button. Will remove in 5.12 or later.
Expand All @@ -138,7 +139,7 @@ def __init__(self, master: ttk.Frame | None = None, **kw):
ttk.Button.__init__(self, master, **kw)


class ColoredButton(tk.Label or tk.Button): # type: ignore
class ColoredButton(tk.Button): # type: ignore
"""Custom t(t)k.ColoredButton class to fix some display issues."""

# DEPRECATED: Migrate to tk.Button. Will remove in 5.12 or later.
Expand Down Expand Up @@ -166,11 +167,14 @@ class OptionMenu(ttk.OptionMenu):
"""Custom ttk.OptionMenu class to fix some display issues."""

def __init__(self, master, variable, default=None, *values, **kw):
style = 'nb.TMenubutton' if sys.platform == 'win32' else ttk.Style().lookup('TMenu', 'background')
menu_background = PAGEBG if sys.platform == 'win32' else ttk.Style().lookup('TMenu', 'background')

super().__init__(master, variable, default, *values, style=style, **kw)
self['menu'].configure(background=menu_background)
if sys.platform == 'win32':
# OptionMenu derives from Menubutton at the Python level, so uses Menubutton's style
ttk.OptionMenu.__init__(self, master, variable, default, *values, style='nb.TMenubutton', **kw)
self['menu'].configure(background=PAGEBG)
else:
ttk.OptionMenu.__init__(self, master, variable, default, *values, **kw)
self['menu'].configure(background=ttk.Style().lookup('TMenu', 'background'))

for i in range(self['menu'].index('end') + 1):
# Workaround for https://bugs.python.org/issue25684
for i in range(0, self['menu'].index('end') + 1):
self['menu'].entryconfig(i, variable=variable)

0 comments on commit e0ef9b5

Please sign in to comment.