I'm making a GUI with a dark theme and would like to save time by setting the default parameters using an option database but only some of the options are working. Options like "background" and "font" are working correctly but other things like changing the activebackground or selectcolor for a Radiobutton do NOT work. Changing the "insertbackground" on an entry widget also doesn't work.
I'm not sure why some options are working and others are not. If I pass in the same parameters when creating the widget it does work. eg:
myRadio = Radiobutton(frame, selectcolor='#FF0000', **otherKwargs)
I tried this two ways.
import tkinter
from tkinter import Tk, ttk, Frame, Entry, Label, Button, Toplevel, BooleanVar, IntVar, Radiobutton, StringVar, Canvas
mw = Tk()
mw.option_readfile('StyleDatabase.txt')
# code here...
mw.mainloop()
The "StyleDatabase.txt" file contains the following:
*background: #000008
*foreground: grey90
*font: '', 11
*Entry*background: #404050
*Radiobutton*selectcolor: #FF0000 <---- This one doesn't work.
# also tried:
*selectcolor: #FF0000
*Radiobutton.selectcolor: #FF0000 <---- Neither worked
I also tried using the mw.option_add() function, none of the following worked:
mw.option_add('*selectbackground', 'blue')
mw.option_add('*Radiobutton*selectbackground', 'blue')
mw.option_add('*Radiobutton.selectbackground', 'blue')
As far as I know there aren't any other ways to do this.
EDIT: Here's a workable script to demonstrate the issue, Python 3.x
import tkinter
from tkinter import Tk, ttk, Frame, Entry, Label, Button, Toplevel, BooleanVar, IntVar, Radiobutton, StringVar, Canvas
class MainUI:
def __init__(self, master):
self.master = master
Label(self.master, text='Hello').pack(side='top')
Entry(self.master).pack(side='top')
Entry(self.master, insertbackground='red').pack(side='top')
Button(self.master, text='Cyan Button').pack(side='top')
mw = Tk()
mw.option_add('*background', 'blue') # works
mw.option_add('*foreground', 'white') # works
mw.option_add('*Button.foreground', 'cyan') # works
mw.option_add('*insertbackground', 'red') # does not work. Works if i pass the argument in when creating the widget.
mw.option_add('*Entry.insertbackground', 'red') # also does not work
mw.option_add('*Entry*insertbackground', 'red') # also does not work
mainUI = MainUI(mw)
mw.mainloop()