So I just learn tkinter and want to create a custom titlebar and change it colors base on login and signup page. I manage to change the color between login frame and signup frame. However I struggle changing the color of the tittle bar, I tried many functions like pack_forget(), lift(), loop frame.winfo_children() and destroy widget
the problem is I cannot manage to remove the frame of title when switching between login and signup page.
for convenient this is the source code : https://github.com/SeakMengs/Sign-in-gui-with-python-tkinter
class tittle():
def __init__(self):
global FrameBG, FontFG, BoxBG, SignupBG, SignupFG, SignupBOX, LoginBG , LoginFG, LoginBOX
global inLogin, inSignup
if inLogin == True:
FrameBG, FontFG, BoxBG = LoginBG, LoginFG, LoginBOX
if inSignup == True:
print('change to purple')
FrameBG, FontFG, BoxBG = SignupBG, SignupFG, SignupBOX
self.root = root
self.titlebar = Frame(root, background=FrameBG, bd=0)
def titleBar(self):
# ? Create my own titlebar
global RunOnce
root.overrideredirect(True)
root.after(10, lambda: self.set_appwindow(root))
# self.titlebar = Frame(root, background=FrameBG, bd=0)
#*----------------------------------------------------------------------------------------------------------------------------------------
# ? these functions copy from https://stackoverflow.com/questions/63217105/tkinter-overridedirect-minimizing-and-windows-task-bar-issues
self.titlebar.bind('<Button-1>', self.SaveLastClickPos)
self.titlebar.bind('<B1-Motion>', self.Dragging)
self.titlebar.bind("<Map>", self.frameMapped) # This brings back the window
#*----------------------------------------------------------------------------------------------------------------------------------------
self.icon = Image.open('asset\\bank.png')
self.icon = self.icon.resize((22, 22))
self.icon = ImageTk.PhotoImage(self.icon)
Label(self.titlebar, text=' Yato Bank', font=('Lexend', 16), bg=FrameBG, fg=FontFG, image=self.icon, compound=LEFT).pack(side=LEFT, pady=10, padx=10)
# ? Open image using pil (for resize purpose)
self.closeIcon = Image.open("asset\\close.png")
self.closeIcon = self.closeIcon.resize((24, 24))
self.closeIcon = ImageTk.PhotoImage(self.closeIcon)
Button(self.titlebar, image=self.closeIcon, command=root.destroy, background=FrameBG, bd=0, activebackground=FrameBG).pack(side=RIGHT, pady=10, padx=10)
self.maximizeIcon = Image.open("asset\\maximize.png")
self.maximizeIcon = self.maximizeIcon.resize((24, 24))
self.maximizeIcon = ImageTk.PhotoImage(self.maximizeIcon)
Button(self.titlebar, image=self.maximizeIcon, command=self.fullScreen, background=FrameBG, bd=0, activebackground=FrameBG).pack(side=RIGHT, pady=10, padx=10)
self.minimizeIcon = Image.open("asset\\minus.png")
self.minimizeIcon = self.minimizeIcon.resize((24, 24))
self.minimizeIcon = ImageTk.PhotoImage(self.minimizeIcon)
Button(self.titlebar, image=self.minimizeIcon, command=self.minimizeGUI, background=FrameBG, bd=0, activebackground=FrameBG).pack(side=RIGHT, pady=10, padx=10)
self.titlebar.pack(expand=0, fill=BOTH)
RunOnce += 1
if RunOnce > 1:
self.titlebar.pack_forget()
self.titlebar.pack(expand=0, fill=BOTH)
self.titlebar.lift()
pass
def startBar(self):
self.titlebar.pack_forget()
tittle().titleBar()
print("Destroyed")
These functions are for switching between signin and signup page and it call class tittle() and its functions
#* switch frame
def startLogin(self):
global inLogin, inSignup
inSignup = False
inLogin = True
# tittle().titlebar.destroy()
# tittle().startBar()
self.form.pack(expand=1)
def changeToSignup(self):
global inLogin, inSignup
inSignup = True
inLogin = False
tittle().startBar()
self.form.pack_forget()
signupPage().startSignup()
def startSignup(self):
global inLogin, inSignup
inSignup = True
inLogin = False
# tittle().titlebar.destroy()
# tittle().startBar()
self.signupFrame.pack(expand=1)
def changeToLogin(self):
global inLogin, inSignup
inSignup = False
inLogin = True
tittle().startBar()
self.signupFrame.pack_forget()
loginPage().startLogin()