I have got a program with GUI (Tkinter) where I want to add a login system to. I programed a login window with a several functions in a separate library Login_v1. The program and de login system works well. However, it seems that a certain process is running on the background causing the computer to freeze (except for the program itself), while when I run both program or login library separately it does runs smoothly without running processes on the back. I think it has something to do with using two windows into one program and going from one window to another, but I don't know how to solve it.
Starting the main program it checks whether it should start the login window. When starting the login window it passes the function start_application through as command to execute in case of a succesfull login. The login window passes through to the main program start_application function a username and the account type.
Here you can find a relevant part of the code of the main program:
import tkinter as tk #GUI Library
import os #For file and directory handling
import Login_v1 as login #Login library
def start_application(Username, User_type):
global mainWindow
global FirstFrame
global SecondFrame
global ThirdFrame
global USERNAME
global USER_TYPE
USERNAME = Username #Received from login
USER_TYPE = User_type #Received from login
load_config_settings() #Load config settings first
load_all_settings(int(FILETYPE_CONFIG)) #Load all settings based on config
root = tk.Tk()
#Create a window as defined in the AppWindow class
mainWindow = AppWindow(root)
#Create a Frame as defined in class MainFrame
FirstFrame = MainFrame(mainWindow)
FirstFrame.grid(row=0, column=1, rowspan=2, sticky="NWES") #Positioning Frame on Window
#Create a Frame as defined in class SearchFrame
SecondFrame = SearchFrame(mainWindow)
SecondFrame.grid(row=0, column=0, sticky="NWES") #Positioning Frame on Window
#Create a Frame as defined in class ScrollFrame
ThirdFrame = ScrollFrame(mainWindow)
ThirdFrame.grid(row=1, column=0, sticky="NWES") #Positioning Frame on Window
root.mainloop()
if __name__ == "__main__":
if os.path.exists(USERS_FILE) == True:
#Start login window
login = login.Login(icon="LegalNotesApp_icon.ico",
users_file=USERS_FILE,
modus="advanced",
command=lambda:start_application(login.username_entry_var.get(), login.account_type))
else:
start_application(Username="Administrator", User_type = "")
Here you can find the relevant part of the login library:
class Login(tk.Tk):
def __init__(self,
title="Login",
command="pass",
accounts={},
users_file="",
modus="simple"):
tk.Tk.__init__(self)
self.resizable(0,0) #Window not resizable
self.attributes("-topmost", 1) #Topmost window
self.focus_force()
#Passing through variables
self.command = command #Action when login is succesful
self.title(title) #Title of window
self.users_dict = accounts #Dictonary of users & passes
self.users_file = users_file #File to load/save dictonary of users & passes
self.modus = modus #Account modus: simple, advanced, custom?
def login_event(self, *args):
#Event when login button is pressed
if self.users_dict != {}: #Check whether users are available
#STEP 1: Check for empty fields
if self.username_entry.get() != "" and self.password_entry.get() != "": #check wether username is not empty
#STEP 2: Check for modus: "simple", "advanced", "custom"?
if self.modus == "simple": #MODUS
if self.password_entry.get() == self.users_dict.get(self.username_entry.get()): #Check password
#Succesful login
self.destroy() #Login window not needed after login
self.command() #Action determined by user
What is causing the process on the background? And how do I prevent it from happening? or what can I do better?