I am making an expense tracker as a fun project. I have encountered an issue where the colour choosing method I am using inside the frame class isn't working, could someone help please?
Here is my code:
import tkinter as tkfrom tkinter import ttk, colorchooser, messageboxclass ExpenseTracker(tk.Tk): def __init__(self): super().__init__() self.title("Expense Tracker") self.geometry("700x700") self.minsize(700, 700) self.login = Login(self) self.mainloop()class Login(tk.Frame): def __init__(self, parent): super().__init__(parent) tk.Label(text="Enter Username:").place(relx=0.5, rely=0.36, anchor=tk.CENTER) tk.Label(text="Enter Password:").place(relx=0.5, rely=0.46, anchor=tk.CENTER) change_colour = tk.Button(text="Background Colour", command=self.change_colour) change_colour.place(relx=0.9, rely=0.1, anchor=tk.CENTER) username_entry = tk.Entry() username_entry.place(relx=0.5, rely=0.4, anchor=tk.CENTER) password_entry = tk.Entry() password_entry.place(relx=0.5, rely=0.5, anchor=tk.CENTER) login_box = tk.Button(text="Login") login_box.place(relx=0.5, rely=0.55, anchor=tk.CENTER) self.grid() def change_colour(self): color = colorchooser.askcolor()[1] self.configure(bg=color)ExpenseTracker()
At first, the login class inherited from "ttk.Frame", which I wanted but I was getting an " unknown option "-bg"" error. Then, I changed it to inherit from "tk.Frame", which stopped the error from happening, but the background still doesn't change when I use the change colour button.