Returning to previous window not working in Python Tkinter -
i new python , trying had designing gui application.i have 3 classes in directory of python project, each 1 projects different window of different size therefore using window.destroy() everytime before call class, in 1 window, have button while trying access menu() function empty window loads up. below codes of 3 classes login, menu , customerdetails respectively. path being followed: login-->menu--> new customer--> button-->(ideal result=menu, result=blank window ).
from tkinter import * tkinter import ttk frontend.menu import menu class login: def log(self): if self.username.get() == "123" , self.password.get() == "123": self.window.destroy() menu() def login(self): # title frame title=frame(self.window, border=2) title.place(relx=0.5, rely=0.2, anchor=center) # addng login form frame frame=frame(self.window,background="#ccd5cc", highlightthickness=2 ) frame.place(relx=0.5, rely=0.45, anchor=center) # frame.pack() # company label company=label(title, text=" rajendra investments :: guwahati",background="#ccd5cc", font=("calibri", 18, "bold")) # self.company.insert(insert," rajendra investments :: guwahati") # self.company.configure(font=("calibri", 18, "bold")) company.pack() # adding heading label headlabel1=ttk.label(frame,text="login credentials",background="#ccd5cc") headlabel1.grid(row=0, column=0, pady=(10, 10), columnspan=2) # username label username=ttk.label(frame,text="username: ",background="#ccd5cc") username.grid(row=1, column=0, pady=(10, 10), padx=(10,0)) # adding input field username self.username = stringvar() e1 = ttk.entry(frame, textvariable=self.username,background="#ccd5cc") e1.grid(row=1, column=1,pady=(10, 10),padx=(0,10)) # password label password=ttk.label(frame,text="password: ",background="#ccd5cc") password.grid(row=2, column=0, pady=(10, 10), padx=(10,0)) # adding input field password self.password = stringvar() e1 = ttk.entry(frame, textvariable=self.password,background="#ccd5cc", show="*") e1.grid(row=2, column=1,pady=(10, 10),padx=(0,10)) # button b1 = ttk.button(frame, text="login", width=9, command=self.log) b1.grid(row=3, column=0,columnspan=2, pady=(0, 10)) def __init__(self): # creating window self.window = tk() self.window.title("finance maester") self.window.minsize(width=500, height=450) self.window.maxsize(width=500, height=450) self.window.resizable(0,0) background_image=photoimage(file="images/123.gif") background_label = label( self.window, image=background_image) background_label.pack() self.login() self.window.mainloop() login()
after login leads menu
from tkinter import * tkinter import ttk frontend.customerdetails import customerform class menu: def call_direct(self,key,value): print(key, value) if key=="new customer" , value=="1": self.window.destroy() customerform() elif key=="old customer" , value=="3": self.window.destroy() elif key=="current customer" , value=="2": self.window.destroy() elif key=="search" , value.strip(" ")!="": self.window.destroy() def menu(self): # frames frame1=frame(self.window,background="#d5e1df") frame1.place(relx=0.2, rely=0.25) frame2=frame(self.window,background="#d5e1df") frame2.place(relx=0.2, rely=0.35) # search label search=ttk.label(frame1, text="search: ",background="#d5e1df") search.grid(row=0, column=0,pady=(10, 10), padx=(0, 10)) # # adding input field search search = stringvar() e1 = ttk.entry(frame1, textvariable=search, background="#ccd5cc", width=27) e1.grid(row=0, column=1, padx=(0, 10)) # search button sb = ttk.button(frame1, text="go", width=15,command=lambda : self.call_direct("search", search.get())) sb.grid(row=0, column=2, padx=(0, 10),) # menu button 1 mb1=ttk.button(frame2, text=" new customer ", command=lambda : self.call_direct("new customer","1")) mb1.grid(row=0, column=0, padx=(0, 10), pady=(10,0)) # menu button 2 mb2=ttk.button(frame2, text=" current customer ", command=lambda : self.call_direct("current customer","2")) mb2.grid(row=0, column=1, padx=(9, 10), pady=(10,0)) # menu button 3 mb3=ttk.button(frame2, text=" old customer ", command=lambda : self.call_direct("old customer","3")) mb3.grid(row=0, column=2, padx=(10, 10), pady=(10,0)) def __init__(self): # creating window self.window = tk() self.window.title("finance maester") self.window.minsize(width=500, height=450) # self.window.maxsize(width=self.window.winfo_screenwidth(), height=self.window.winfo_screenheight()) # self.window.resizable(0,0) self.window.configure(background="#d5e1df") # self.window.attributes("-toolwindow"=> 1) # self.background_image=photoimage(file="images/123.gif") # self.background_label = label( self.window, image=self.background_image) # self.background_label.pack() label=label(self.window,text="rajendra investments :: guwahati",font=('calibri',12,"bold"),background="#d5e1df") # self.label.place(relx=0.05, rely=0.01) label.pack(side="top", anchor="w", padx=(50, 0), pady=(10, 0)) self.menu() self.window.mainloop()
new customer form
from tkinter import * tkinter import ttk frontend.menu import menu frontend.installmentdetails import installmentdetails class customerform(): def redirect(self, value): self.window.destroy() if value=="back": menu() elif value=="continue": installmentdetails() def custform(self): # frames frame1=frame(self.window,background="#d5e1df") frame1.pack(side="left", anchor="nw", padx=(50, 0), pady=(50, 0)) frame2=frame(self.window,background="#d5e1df") frame2.pack(side="left", anchor="ne",pady=(50, 0), padx=(0,50)) # frame1 blocks starts here # block 1 starts here statement_file_no=ttk.label(frame1,background="#d5e1df",text="statement file number : ", ) statement_file_no.grid(row=0, column=0, padx=(10, 10), pady=(10, 10), sticky="w" ) stfileno=stringvar() statement_file_no_entry=ttk.entry(frame1, textvariable=stfileno, width=25) statement_file_no_entry.grid(row=0, column=1, padx=(10, 10), pady=(10, 10), sticky="w") date=ttk.label(frame1,background="#d5e1df", text="date : ") date.grid(row=0, column=2 , padx=(10, 10), pady=(10, 10), sticky="e") datetext=stringvar() date_entry=ttk.entry(frame1, textvariable=datetext, width=22) date_entry.grid(row=0, column=3, padx=(10, 10), pady=(10, 10), sticky="w") hirer_name=ttk.label(frame1,background="#d5e1df",text="hirer name : ") hirer_name.grid(row=1, column=0 , padx=(10, 10), pady=(10, 10), sticky="w") hname=stringvar() hirer_name_entry=ttk.entry(frame1, textvariable=hname, width=73) hirer_name_entry.grid(row=1, column=1, columnspan=3, padx=(10, 10), pady=(10, 10), sticky="w" ) address=ttk.label(frame1,background="#d5e1df", text="address : ") address.grid(row=2, column=0, padx=(10, 10), pady=(10, 10), sticky="w") address=stringvar() address_text=text(frame1, height=2, width=55) address_text.grid(row=2, column=1, columnspan=3, padx=(10, 10), pady=(10, 10), sticky="w") # block 1 ends here # button sb = button(frame2, text=" back", width=20, font=("calibri", 12),command=lambda: self.redirect("back")) sb.grid(row=9, column=0, columnspan=3, padx=(10, 30), pady=(20, 15), rowspan=2) # submit button sb = button(frame2, text=" continue", width=20, font=("calibri", 12),command=lambda: self.redirect("continue")) sb.grid(row=9, column=1,columnspan=3, padx=(10, 10), pady=(20, 15), sticky="e") def __init__(self): # creating window self.window = tk() self.window.title("finance maester") # self.window.minsize(width=500, height=450) # self.window.maxsize(width=500, height=450) # self.window.resizable(0, 0) w, h = self.window.winfo_screenwidth(), self.window.winfo_screenheight() self.window.geometry("%dx%d+0+0" % (w, h)) self.window.configure(background="#d5e1df") # self.window.attributes("-toolwindow"=> 1) # self.background_image=photoimage(file="images/123.gif") # self.background_label = label( self.window, image=self.background_image) # self.background_label.pack(anchor="center") self.label = label(self.window, text="rajendra investments :: guwahati", font=('calibri', 12, "bold"), background="#d5e1df") # self.label.place(relx=0.05, rely=0.01) self.label.pack(side="top", anchor="w", padx=(50,0), pady=(10,0)) self.custform() self.window.mainloop()
in class customer when try call menu if button pressed, empty window. have no idea why.
Comments
Post a Comment