python - Login and show menu items by if -


i'm trying create login tkinter entry. compare input password , if correct supposed access more stuff in menu bar.

if understand correctly need update window in order menu update, cant figure out how. , variable "moberg" don't seems update true. might 1 global(?) , other 1 belongs class. cant figure out how make work either.

here sample of i've done far.

from tkinter import * moberg="no" class pcmsyntax(frame):     def update():         print("updated") #only visual, remove later         app.mainloop.after(1, update)      def __init__(self, master):         super().__init__(master)         self.pack(fill=both, expand=true)         self.initui()       def initui(self):         menubar = menu(self.master)         self.master.config(menu=menubar)         syntaxmenu = menu(menubar, tearoff=false)         submenu = menu(syntaxmenu)         syntaxmenu.add_cascade(label='arithmetic exp', underline=0, command='')         syntaxmenu.add_cascade(label='assign & compare', underline=0, command='')         syntaxmenu.add_separator()         syntaxmenu.add_cascade(label='math', menu=submenu, underline=0)         submenu.add_command(label="abs()", command='')         if moberg == true:             syntaxmenu.add_cascade(label='no public access', menu=submenu, underline=0)             submenu.add_command(label="onlyforlabtech()")            menubar.add_cascade(label="syntax", underline=0, menu=syntaxmenu)         menubar.add_cascade(label="login", underline=0, command=self.onlogin)       def onlogin(self):         self.newwindow = toplevel(self.master)         self.app = password(self.newwindow)    class password():     def __init__(self, master):         self.master = master         self.frame = frame(self.master)         self.pwd = entry(self.master, width=30, bg="whitesmoke", foreground="whitesmoke")         self.pwd.pack()         self.verifybutton = button(self.frame, text = 'verify', width = 25, command = self.verify_password)         self.verifybutton.pack()         self.frame.pack()      def verify_password(self):         user_entry = self.pwd.get()          if str(user_entry) == "test":             moberg=true             print(moberg) #only visual, remove later             pcmsyntax.update             self.master.destroy()         else:             moberg=false             print(moberg) #only visual, remove later             self.master.destroy()  def main():     root = tk()     root.geometry("560x600")     app = pcmsyntax(master=root)     app.mainloop()  if __name__ == '__main__':     main() 

you achieve you're looking below:

from tkinter import *  class app:     def __init__(self, root):         self.root = root         self.public = frame(self.root, borderwidth=1, relief="solid") #public, visible frame         self.hidden = frame(self.root, borderwidth=1, relief="solid") #hidden, private frame         self.label1 = label(self.public, text="this text , on here public.") #this inside public frame , visible         self.entry1 = entry(self.public) #so         self.label2 = label(self.hidden, text="this text , on here hidden , appears after login.") #this 1 in hidden frame , private before login         self.button1 = button(self.public, text="login", command=self.command) #this in public frame         self.public.pack(side="left", expand=true, fill="both") #we pack public frame on left of window         self.label1.pack() #then pack widgets both frames here , below         self.entry1.pack()         self.label2.pack()         self.button1.pack()     def command(self): #whenever login button pressed called         if self.button1.cget("text") == "login" , self.entry1.get() == "password": #we check if button in login state or not , if password correct             self.hidden.pack(side="right", expand=true, fill="both") #if pack hidden frame makes , it's contents visible             self.button1.configure({"text": "logout"}) #we set button logout state         elif self.button1.cget("text") == "logout": #if button in logout state             self.hidden.pack_forget() #we pack_forget frame, removes , it's contents view             self.button1.configure({"text": "login"}) #and set button login state  root = tk() app(root) root.mainloop() 

this self explanatory , isn't i've explained what's happening.

this 1 way of many of achieving you're looking for.

i'd point out login systems complicated , if you're looking use serious or package sell way have done not secure.

i'd recommend looking @ other ways people handle sensitive information in tkinter.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -