python 3.x - Accessing variable from one class to another -
i new python , need code. want access "usser" variable in "login" class mainmenu class. appreciated. thank in advance , have great day.
class login (tk.frame): def __init__(self, parent, controller): tk.frame.__init__(self, parent) self.controller = controller username = ttk.label(self, text="username: ") password = ttk.label(self, text="password: ") username.grid(row=0, column=0, sticky='nsew') password.grid(row=1, column=0, sticky='nsew') usernamee = ttk.entry(self) passworde = ttk.entry(self, show='*') usernamee.grid(row=0, column=1, sticky='nsew') passworde.grid(row=1, column=1, sticky='nsew') backbutton = ttk.button(self, text="sign up", command=lambda:controller.show_frame(newhere)) backbutton.grid(row=4, column=0, sticky='nsew') loginbutton = ttk.button(self, text="log in") loginbutton.grid(row=4, column=1, sticky='nsew') def checklogin(event): global active try: accounts = np.load("dictionary.npy").item() except filenotfounderror: messagebox.showerror("account error", "the account not found in our database credentials provided. sign , try again.") if usernamee.get().rstrip() in accounts , passworde.get() != '': check = accounts[usernamee.get().rstrip()] if passworde.get() == check: self.usser = usernamee.get() messagebox.showinfo("success!", "welcome, "+self.usser) usernamee.delete(0, 'end') passworde.delete(0, 'end') controller.show_frame(mainmenu) elif usernamee.get().rstrip() in accounts , passworde.get() != check: messagebox.showerror("error 511", "the account not found in our database credentials provided. double check them , try again.") usernamee.delete(0, 'end') passworde.delete(0, 'end') else: messagebox.showerror("error 510", "the account not found in our database credentials provided. double check them , try again.") usernamee.delete(0, 'end') passworde.delete(0, 'end') loginbutton.bind("<button-1>", checklogin)
the end of log in window
class mainmenu(tk.frame): def init(self, parent, controller): tk.frame.init(self, parent) self.controller = controller activeuser = ttk.label(self, text="logged in as: ") activeuser.grid(row=0, column=3, sticky='nsew') vers = '1.0' version = ttk.label(self, text = "version: "+ vers) version.grid(row=1, column=3, sticky='nsew') logout = ttk.button(self, text='logout') logout.grid(row=2, column=3, sticky='nsew')
Comments
Post a Comment