I am trying to make a GUI base login / register program. What i have done is that i have made a file named login and another file named register, in those i have written code for just that particular instance (let say login). In gist , i have programmed each individual windows and now i am not getting desired result when i run it. i run it by making a funtion of those file and importing them into a common file and than run it on button press.
For login.py:
from tkinter import *from tkinter import messageboxfrom functions import *def login(): root = Tk() root.geometry("200x200+750+400") #adding usernme parameters username_var = StringVar() username_entry = Entry(textvariable=username_var).grid(row = 0 , column = 1) username_label = Label(text="Username").grid(row = 0 , column = 0) #addding password parameters password_var = StringVar() password_entry = Entry(textvariable=password_var).grid(row = 1 , column = 1) password_label = Label(text="Password").grid(row = 1 , column = 0) # adding button to get the values #making a function to add in the button temp_list = [] def get_values_and_check(value , value2): x = value.get() y = value2.get() temp_list.append(x) temp_list.append(y) #getting the ocrrect username and password from the csv file def correct_user_and_password(): data = only_read_csv("user_info") for i in range(len(data)): if x in data[i] and y in data[i]: return True"""else: return False""" auth_bool = correct_user_and_password() if auth_bool == True: messagebox.showinfo("Login successfully" , "you've logged in successfully") return True elif auth_bool == False: messagebox.showwarning("Error logging in" , "shame on you you bastard") return False data_button = Button(text = "confirm" , command=lambda : get_values_and_check(username_var , password_var)).grid(row = 2 , column = 1) root.mainloop()
and for register.py
from functions import *from tkinter import * from tkinter import messageboxdef register(): root = Tk() root.geometry("300x200+750+400") #user parameter username_var = StringVar() username_entry = Entry(textvariable=username_var).grid(row = 0 , column = 1) username_label = Label(text="Username").grid(row = 0 , column = 0) #addding password parameters password_var = StringVar() password_entry = Entry(textvariable=password_var).grid(row = 1 , column = 1) password_label = Label(text="Password").grid(row = 1 , column = 0) password_again_var = StringVar() password_again_entry = Entry(textvariable=password_again_var).grid(row = 2 , column = 1) password_again_label = Label(text="Password, Again!!").grid(row = 2 , column = 0) def authenticate(value , value2 , value3): x = value.get() y = value2.get() z = value3.get() temp_data = [ x , y] if y == z: appendrow_csv("user_info" , temp_data) messagebox.showinfo("success" , "your Account has been added successfully") return True elif y!= z: messagebox.showerror("Error" , "password dosent match") return False verify_button = Button(text = "confirm" , command = lambda : authenticate(username_var , password_var , password_again_var)).grid(row = 3 , column = 0) root.mainloop()register()
i import these two into another file named home since it is the first page which gives the options of login or register ie:
from tkinter import *from login import *from register import *root = Tk()root.geometry("200x200+750+400")register_button = Button(text="register" , command = register()).grid(row = 0 , column = 0)login_button = Button(text="login" , command= login()).grid(row = 0 , column = 1)root.mainloop()
the problem is that the register file is being run first and not on the button click. everything gets overlayed.