Skip to content

Explaining a TKINTER Register/sign up app in Python | LBOET | HOXFRAMEWORK

Posted in VIDEOS

Explaining a TKINTER Register/sign up app in Python | LBOET | HOXFRAMEWORK

Hello and welcome,
Today we are making a UI in Tkinter with Python, it is going to be a register system in which user inputs data, clicks a button,
and the data is stored in our text file.



Here is the python code:

from tkinter import *

def saveuser():
  #ACCEPTING THE INPUT
  firstname_info = firstname.get()
  lastname_info = lastname.get()
  if firstname_info == "":
    print("No name entered. Quitting...")
    #firstname_entry.delete(0, END)
    return None
  if lastname_info == "":
    print("No last name entered...")
    #lastname_entry.delete(0, END)
    return None
  #we are using return here and not Quit because quit completely quits while
  #return will quit only this function and return us back to our GUI to enter
  #the name again.
    
  
 
  #reorginizing our data to look nicer
  converterThing = "\n>" + firstname_info + "," + lastname_info + ";"


  #Printing out our entry.
  print("User ", firstname_info, " has been registered successfully")
 
  #Finally saving the entered data into our text file while
  #conserving all the previous data as well
  file = open("user.txt", "a")
  operationManager = str(converterThing)
  file.write(operationManager)
  file.close()
  #wrote everything and closed it

  #making sure that, after we press submit, or fields clear for the next input
  firstname_entry.delete(0, END)
  lastname_entry.delete(0, END)
  
#Setting up a screen in tkinter
screen = Tk()
#adding the resolution to it 
screen.geometry("500x500")
#adding a custom title (<title> in html)
screen.title("Register thing")
#adding a heading , like a title Inside the app (<h1> in html)
heading = Label(text = "Welcome, Make sure you register.", bg = "grey", fg = "black", width = "500", height = "3")
#using .pack instead of .place for the heading; 
heading.pack()

#Writing out our labels so user knows what to enter
firstname_text = Label(text = "Firstname * ",)
lastname_text = Label(text = "Lastname * ",)
#placing our labels on a place we like 
firstname_text.place(x = 10, y = 70)
lastname_text.place(x = 10, y = 140)

 
#defining the type of data our entries are going to be
firstname = StringVar()
lastname = StringVar()

#Making our form boxes - entry boxes
firstname_entry = Entry(textvariable = firstname, width = "30")
lastname_entry = Entry(textvariable = lastname, width = "30")
#placing them
firstname_entry.place(x = 5, y = 100)
lastname_entry.place(x = 5, y = 180)

#adding a button and placing it
register = Button(screen,text = "Register", width = "30", height = "2", command = saveuser, bg = "grey")
register.place(x = 10, y = 250)

greeting_bye = Label(text = "Thank you for using my program. Have a nice day")
greeting_bye.place(x=90 , y = 450)


---------------------------------------------------------------------
,a user.txt file, and a batch file.


And our batch file only has one line:


echo USERNAME,LASTNAME; > user.txt





thank you for visiting and have a nice day.