I'm trying to create a program in python tkinter which user first have to login, then the first page is closed and new one opens with some buttons inside.
button must change it's color and text on click but it does not do anything
from tkinter import *
def button_clicked(button):
Button(button).configure(bg="red", text="not Active")
def open_setting_page():
loginPage.destroy()
setting_page = Tk()
setting_page.title("Setting")
setting_page.geometry("400x300")
b2 = Button(setting_page, text="Active", height=5, width=10, bg="green",command=lambda:button_clicked(b2)).grid(row=0, column=0)
b3 = Button(setting_page, text="Active", height=5, width=10, bg="green",command=lambda:button_clicked(b3)).grid(row=0, column=1)
setting_page.mainloop()
#program starts here
loginPage = Tk()
loginPage.title("Security System")
loginPage.geometry("400x300")
Label(text="\n\n\n\n").pack()
l1 = Label(text="Enter Password:")
l1.pack()
password_entry = Entry()
password_entry.insert(0, "Enter Your Password...")
password_entry.pack()
b1 = Button(text="Login", command=open_setting_page)
b1.pack()
loginPage.mainloop()
I want the buttons color and text be changed on click but noting happens when I click it.
button_clicked()is creating a brand-new Button, calling.config()on it uselessly, and then throwing the new Button away. If you want to affect the Button that was passed as thebuttonparameter, dobutton.config(...).b2/b3, rather than the result of calling.grid()on them. Do the geometry management as a separate statement.tk.Tkwindows you have, you only need 1.mainloop()so you can remove thesetting_page.mainloop()