Mar-28-2021, 06:19 PM
(Mar-24-2021, 03:54 AM)deanhystad Wrote: Multichoice_button_0 and Multichoice_button_1 are both None. If you want to keep a handle to these widgets you need to split making the button and placing the button into two separate commands. If you don't need the handles, don't pretend you are saving them in a variable.
This is a big problem:
LoginWindow = tkinter.Tk()This is how you initialize tkinter. It also creates a window and returns the window handle, but it's primary function is to prepare tkinter for use in your program. This is not how you create a window for a dialog, or a second main window. You can only call Tk() once in your program.
Similarly this is a big problem
LoginWindow.mainloop()
A tkinter program only gets to call mainloop() once. mainloop() will run until the program is shut down (quit) or crashes.
If you fix those problems the next problem you encounter is this:
while login_verified == False and run_program == True:Now that the mainloop() is removed, there is noting preventing this loop from running forever and creating millions of login windows.
There are so many changes required to your code to make it work that I would throw it away and start from scratch. I started by making a login dialog that gets the username and password. It is based off the tkinter.simpledialog.Dialog class. I override the body and buttonbox methods to create my own controls.
import tkinter as tk from tkinter import simpledialog, messagebox class LoginDialog(simpledialog.Dialog): def __init__(self, parent, title='Login'): super().__init__(parent, title) def body(self, frame): """Places controls in the body of the dialog. Overrides base method""" self.username = None self.password = None self.cancelled = False tk.Label(frame, text="Username: ").grid(row=0, column=0, padx=5, pady=5) self.username_entry = tk.StringVar() tk.Entry(frame, textvariable=self.username_entry).grid(row=0, column=1, pady=10) tk.Label(frame, text="Password: ").grid(row=1, column=0) self.password_entry = tk.StringVar() tk.Entry(frame, textvariable=self.password_entry, show="*") \ .grid(row=1, column=1) def buttonbox(self): """Make buttons at the bottom of the dialog. Overrides base method""" tk.Button(self, text="Ok", width="10", command=self.ok_pressed) \ .pack(side='left', padx=5, pady=5) tk.Button(self, text="Cancel", width="10", command=self.cancel_pressed) \ .pack(side='right', padx=5, pady=5) def ok_pressed(self): self.username = self.username_entry.get() self.password = self.password_entry.get() self.destroy() def cancel_pressed(self): self.cancelled = True self.destroy() def login(): dialog = LoginDialog(root) if dialog.cancelled: print('Login cancelled') elif dialog.username and dialog.password: print('Username', dialog.username, '\nPassword', dialog.password) else: messagebox.showerror('Login Failed', 'Username and/or Password are Incorrect') root = tk.Tk() tk.Button(root, text='Push Me', command=login).pack() root.mainloop()You can place the password processing in the login() function. Use tkinter Messagebox windows to display messages about successful or unsuccessful login attempts.