Creating a complex login and registering system in tkinter
I am creating a program in python 3.3, whiles using tkinter, which should register the user’s personal information such as their email first and second name. so far the user can register themselves and their information will be saved in a file. However, there is an error. if the user has already created an account, when they enter their login details and click “submit”, the program doesnt read the file and portrays nothing. therefore, i want the program to read if the user’s details exist in the file or not.
Here is my code:
def init_screen(self):
self.MainScreen.title("Sonico Services")
self.MainScreen.configure(background = "#ffff00")
self.pack(fill=BOTH, expand=1)
RegisterButton = Button(self, text="Register", bg = "red", fg = "yellow",command=self.User_Register)
RegisterButton.place(x=200,y=100)
LoginButton=Button(self,text="Login",bg="red",fg="yellow",command=self.User_Login)
LoginButton.place(x=270,y=100)
def User_Register(self):
Firstname=Label(application,text="First Name: ",bg="yellow",fg="red").grid(row=30,column=7)
Secondname=Label(application,text="Second Name: ",bg="yellow",fg="red").grid(row=30,column=10)
Emailtag=Label(application,text="Email address: ",bg="yellow",fg="red").grid(row=15,column=7)
Password=Label(application,text="Password : ",bg="yellow",fg="red").grid(row=35,column=7)
SubmitButton=Button(self,text="Submit",bg="red",fg="yellow",command=self.File_Manipulation)
SubmitButton.place(x=140,y=100)
EntryBox1=Entry(application)
EntryBox2=Entry(application)
EntryBox3=Entry(application)
EntryBox4=Entry(application)
EntryBox1.grid(row=30,column=12)
EntryBox2.grid(row=30,column=8)
EntryBox3.grid(row=15,column=8)
EntryBox4.grid(row=35,column=8)
global EntryBox1
global EntryBox2
global EntryBox3
global EntryBox4
def File_Manipulation(self):
with open("Client Data.txt","w ")as client_file:
EB=EntryBox1.get()
EB2=EntryBox2.get()
EB3=EntryBox3.get()
EB4=EntryBox4.get()
infocombo=EB (",") EB2 (",") EB3 (",") EB4 ("n")
client_file.write(infocombo)
def User_Login(self):
Firstname=Label(application,text="First Name: ",bg="yellow",fg="red").grid(row=30,column=7)
Password=Label(application,text="Password : ",bg="yellow",fg="red").grid(row=35,column=7)
EntryBox1=Entry(application)
EntryBox4=Entry(application)
EntryBox1.grid(row=30,column=8)
EntryBox4.grid(row=35,column=8)
SubmitButton=Button(self,text="Submit",bg="red",fg="yellow",command=self.Data)
SubmitButton.place(x=140,y=100)
EB4=EntryBox4.get()
EB1=EntryBox1.get()
global EB1
global EB4
def Data(self):
data=open("Client Data.txt","w ")
read=data.readlines()
for line in read:
if (EB4 EB1) in line:
WelcomeLabel=Label(application,text="Welcome! you have successfully logged in",bg="yellow",fg="red").grid(row=30,column=10)
else:
ExitLabel=Label(application, text= "Your account does not exist, please register first",bg="yellow",fg="red").grid(row=30,column=10)
How to create a password entry field using tkinter
If you don’t want to create a brand new Entry widget, you can do this:
myEntry.config(show="*");
To make it back to normal again, do this:
myEntry.config(show="");
I discovered this by examining the previous answer, and using the help function in the Python interpreter (e.g. help(tkinter.Entry) after importing (from scanning the documentation there). I admit I just guessed to figure out how to make it normal again.
Python-tkinter-basic login form
I am trying to make a basic login form. I’m having trouble with passing values to my function which checks the username and password.
Summary
In this tutorial of Python Examples, we learned to create a Login Form in Python GUI application using tkinter.