Python GUI Registration Form Using Tkinter

Python GUI Registration Form Using Tkinter

GUI Registration Form Using Tkinter
GUI Registration form created using Tkinter GUI toolkit that takes the data from the users,performs necessary validations and   stores the data into the .xlsx file

Install these necessary packages if required- 
pip install validate_email    - FOR EMAIL_VALIDATION
pip install openpyxl          - FOR WORKING WITH .xlsx FILE
pip install python-tk         - FOR TKINTER
 Create excel.xlsx file in the directory of file.

Program Files - 

# ************************************************************************************************************

from tkinter import *
import datetime
from tkinter import messagebox
import re
from validate_email import validate_email

root = Tk()

class Registration_Form:
    _params = []    # Protected Member can be accessed  within class or subclass
    # Private Members of the class
    __entry_1 = Entry()
    __entry_2 = Entry()
    __entry_3 = Entry()
    __ck = StringVar()
    __c2 = StringVar()
    __c3 = StringVar()
    __c4 = StringVar()
    __entry_4b = Entry()
    __var = IntVar()
    __entry_7 = Entry()
    __entry_8 = Entry()
    # ----------------------------
    def __init__(self):
        self._params = ['Himesh','Singh','','+91','12121','Male','12345','12345'

    def __del__(self):
        self._params = []

    def special_match(self,strg, search=re.compile(r'[^a-zA-Z.]').search):

        return not bool(search(strg))

    def num_match(self,strg, search=re.compile(r'[^0-9.]').search):

        return not bool(search(strg))

    def mainget(self):

        fname =  self.__entry_1.get()
        lname =  self.__entry_2.get()
        mail  =  self.__entry_3.get()
        code  =  self.__ck.get()
        YeaR  =  self.__c2.get()
        MontH =  self.__c3.get()
        DatE  =  self.__c4.get()
        mob   =  self.__entry_4b.get()
        GendR =  self.__var.get()
        Pass  =  self.__entry_7.get()

        if GendR==1:

        date_format = '%Y-%m-%d'
            date_string = YeaR + '-' + MontH + '-' + DatE
            datetime.datetime.strptime(date_string, date_format)
        except ValueError:

        if self.special_match(fname)==False or self.special_match(lname)==False:
            messagebox.showinfo("Error!", "First name and last name should only have Characters")
        elif validate_email(mail)==False:
            messagebox.showinfo("Error!", "Please enter valid email(")
        elif self.num_match(mob)==False:
            messagebox.showinfo("Error!", "Mobile should contain only numbers")
        elif len(Pass)<8:
            messagebox.showinfo("Error!", "Password Must be atleast 8 characters long")
            messagebox.showinfo("Error!", "Password and Confirm-Password Field didn't match")
        elif flag==1:
            messagebox.showinfo("Error!", "Please select a valid date of birth")
            ch = messagebox.askyesno("Submit", "Do you Want to Submit?")
            if ch==True:

        self._params = [fname,lname,mail,code,mob,GendR,Pass, Conf_Pass,date_string,YeaR,MontH,DatE]
        self._params = self._params[:-3]

    def layout(self):

        root.title('Registration Form')
        self.pic = PhotoImage(file="background.png")
        ba__ckground_label = Label(image=self.pic)
        ba__ckground_label.pack(), y=0, relwidth=1, relheight=1)
        ba__ckground_label.image = self.pic
        canvas = Canvas(root,width=720,height=800,bg="grey")
        label=Label(canvas,text="Registration Form",font=("Times",30,"bold"),fg="brown4",bg="snow3",),y=30)
        label1=Label(canvas,text="First Name",font=("Times",14),fg="black",bg="snow3",),y=150)
        self.__entry_1= Entry(canvas,bg="white",bd=4),y=150)
        label2=Label(canvas,text="Last Name",font=("Times",14),fg="black",bg="snow3",),y=150)
        self.__entry_2= Entry(canvas,bg="white",bd=4),y=150)
        label3=Label(canvas,text="Email ",font=("Times",14),fg="black",bg="snow3",),y=220)
        self.__entry_3= Entry(canvas,bg="white",width=50,bd=4),y=220)

        list1 = ['+91','+54','+880','+32','+1','+20','+49','+972','+39','+977','+7','+44','+380'];

        self.__entry_4b= Entry(canvas,bg="white",width=39,bd=4),y=290)
        label_5 = Label(canvas, text="Gender",font=("Times", 14),fg="black",bg="snow3"),y=360)

        Radiobutton(canvas, text="Male",padx = 10, variable=self.__var, value=1,bg="snow3").place(x=180,y=360)
        Radiobutton(canvas, text="Female",padx = 20, variable=self.__var, value=2,bg="snow3").place(x=250,y=360)

        label6=Label(canvas,text="Date of Birth",font=("Times",14),fg="black",bg="snow3"),y=430)

        list2 = []
        for i in range(1980,2017):


        list3 = []
        for i in range(1,13):


        list4 = []
        for i in range(1,32):


        self.__entry_7= Entry(canvas,bg="white",width=50,show="*",bd=4),y=500)
        label8=Label(canvas,text="Password Must be atleast 8 characters long",font=("Times",7),fg="black",bg="snow3",),y=530)

        self.__entry_8= Entry(canvas,bg="white",width=50,show="*",bd=4),y=570)
        w = Button(canvas,text="Submit",width=20,height=2,bd=4,font=("Times",10,"bold"),bg="brown",command=self.mainget),y=640)

class Store_data(Registration_Form): # Derived class of Super class Registration_Form (Inheritance)
    def __init__(self,sheet):
        self.sheet = sheet

    def __del__(self):

    def excel(self):
        # resize the width of columns in
        # excel spreadsheet
        self.sheet.column_dimensions['A'].width = 20
        self.sheet.column_dimensions['B'].width = 20
        self.sheet.column_dimensions['C'].width = 30
        self.sheet.column_dimensions['D'].width = 20
        self.sheet.column_dimensions['E'].width = 10
        self.sheet.column_dimensions['F'].width = 30
        self.sheet.column_dimensions['G'].width = 30

        # write given data to an excel spreadsheet
        # at particular location
        self.sheet.cell(row=1, column=1).value = "First Name"
        self.sheet.cell(row=1, column=2).value = "Last Name"
        self.sheet.cell(row=1, column=3).value = "Email"
        self.sheet.cell(row=1, column=4).value = "Mobile Number"
        self.sheet.cell(row=1, column=5).value = "Gender"
        self.sheet.cell(row=1, column=6).value = "Date of Birth"
        self.sheet.cell(row=1, column=7).value = "Password"

    def insert(self):

        current_row = self.sheet.max_row
        current_column = self.sheet.max_column
        self.sheet.cell(row=current_row + 1, column=1).value = self._params[0]
        self.sheet.cell(row=current_row + 1, column=2).value = self._params[1]
        self.sheet.cell(row=current_row + 1, column=3).value = self._params[2]
        self.sheet.cell(row=current_row + 1, column=4).value = self._params[3]+self._params[4]
        self.sheet.cell(row=current_row + 1, column=5).value = self._params[5]
        self.sheet.cell(row=current_row + 1, column=6).value = self._params[8]
        self.sheet.cell(row=current_row + 1, column=7).value = self._params[7]


from openpyxl import *
from classes import Store_data,root

def main():
        wb = load_workbook('excel.xlsx')
        sheet =
        obj1 = Store_data(sheet)
    except PermissionError:
        print('Permission denied : excel.xlsx file is already opened for other use')


from main import main

if __name__ == "__main__":


Input & Output:-

  • Run the __ main __ .py file

A window will appear on the screen that will look like this - 
Enter the details required that will be checked against certain validations and then finally submit
and the given details will be stored into the excel.xlsx file that will look similar to this -

More Articles of abhijeet singh:

Name Views Likes
Python program to find diameter of a binary tree 820 16
Python program to find sum of all leaf nodes of binary tree 357 18
Python program to find height of a tree using recursion 385 16
Python program to find sum of all nodes in a binary tree 385 15
Python program to check whether a given binary tree is complete or not using recursion 322 18
Python program to check whether a binary tree is a full binary tree or not using recursion 428 30
Python program to convert a given binary search tree to doubly linked list 356 20
Python program to find K%u2019th largest element in binary search tree 342 25
Python program to find lowest Common Ancestor in a binary search tree 368 21
Python program to find k-th smallest element in binary search tree 324 17
Python program to find the node having maximum value in a binary search tree 327 19
Python program to find the node having minimum value in a binary search tree 385 18
Python program to construct binary search tree from given preorder traversal 377 18
Python Program to Implement Queue using two Stacks 404 19
Python Program to count and display occurence of a given Character and lines not starting with given Character 350 18
Python Program to find number of alphabets and number of lines in a file 303 17
Python Program to write numbers 1 to 100 in a file 327 17
Python Program to find number of words in the file 299 12
Python Program to create a file,find size of a file and copy content of one file in another 335 22
Python Program to create and delete a File 350 21
Python Program to demonstrate Monkey Patching 317 11
Python Program to find Sum of list (with string types) 344 21
Python program to create a list of tuples from given list having number and its cube in each tuple 435 18
Python Program to find missing number in a given integer array of 1 to 100 477 23
Python Program to perform files compression to tar file and extract a tar file 298 14
Python Program to demonstrate Various list Functions 444 15
Python GUI Registration Form Using Tkinter 916 25
Python Automated tool to convert Plain Text to Formatted text using Pygments 413 21
Python Program to Generate random numbers 327 20
Python Program to Swap two strings 376 20
Python Program to Perform Set Operations 354 22
Python Program to Find the Transpose of a Given Matrix 385 18
Python Program to Perform Addition,Subtraction and Multiplication of two Matrices 2192 23
Python Program to Calculate Permutation(nPr) and Combination(nCr) 712 23
Python Program to Find the Factorial of a Given Number 297 13
Python Program to Print the Fibonacci Sequence ( without Recursion) 367 26
Python Program to Calculate the Perimeter of a Square 373 28