I want to make background with color in my GUI with 2 tabs, and i run into this problem, maybe some advice?
here is the code:
colors = ["Blue", "Gold", "Red"]
def radCall():
radSel=radVar.get()
if radSel == 0: tab1.configure(bg=colors[0])
elif radSel == 1: tab1.configure(bg=colors[1])
elif radSel == 2: tab1.configure(bg=colors[2])
radVar = tk.IntVar()
radVar.set(99)
for col in range(3):
curRad = tk.Radiobutton(mighty, text=colors[col], variable=radVar,
value=col, command=radCall)
curRad.grid(column=col, row=13, sticky=tk.W)
and here is the problem:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1892, in __call__ >C:/Users/HP/
return self.func(*args) top/Kuliah/Se
File "c:\Users\HP\Desktop\Kuliah\Semester 2\Information TechnologI_jualbeli_Day\Python\week5\Informasi Jual Beli\GUI_jualbeli_Dazan.py", line 277, in radCall
if radSel == 0: tab1.configure(bg=colors[0])
File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1646, in configure
return self._configure('configure', cnf, kw)
File "C:\Users\HP\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1636, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: unknown option "-bg"
any idea?
To play around with themes of ttk widgets, you should use Style, which is like:
s = ttk.Style()
s.configure('first.TFrame',background='red')
s.configure('second.TFrame',background='green')
s.configure('third.TFrame',background='blue')
Then your if statements would be:
def radCall():
radSel=radVar.get()
if radSel == 0: tab1.configure(style='first.TFrame')
elif radSel == 1: tab1.configure(style='second.TFrame')
elif radSel == 2: tab1.configure(style='third.TFrame')
Also in your case, you have to define, colors on top and then use colors[0] and so on, with configure().
You could also try this out to create just one theme and keep editing it:
s = ttk.Style()
.... # Rest of code
def radCall():
radSel=radVar.get()
if radSel == 0:
s.configure('custom.TFrame',background=colors[0])
tab1.configure(style='custom.TFrame')
elif radSel == 1:
s.configure('custom.TFrame',background=colors[1])
tab1.configure(style='custom.TFrame')
elif radSel == 2:
s.configure('cusom.TFrame',background=colors[2])
tab1.configure(style='custom.TFrame')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With