How to create a Login form using tkinter GUI

 

In this section, with Label, Entry and Button widget, we will design a simple form to allow user to enter username and password.


below is the code for the form for above image without any functionality 


#program

try:
from Tkinter import *
except:
from tkinter import *


mw = Tk()

mw.geometry(
"600x100+50+50")
mw.title(
"AETies : Automation Expert Technologies")
mw.config(
background='#eeeeee')

f1 = Frame(mw
, bg='#eeeeee')
f1.pack()

l1 = Label(f1
, text=' Username :\t', bg='#eeeeee').pack(side=LEFT)
u_en = Entry(f1
, width=20)
u_en.pack(
side=LEFT)

f2 = Frame(mw
, bg='#eeeeee')
f2.pack()
l2 = Label(f2
, text=' Password :\t', bg='#eeeeee').pack(side=LEFT)
p_en = Entry(f2
, width=20)
p_en.pack(
side=LEFT)

btn = Button(mw
, text=' Login ').pack()

mainloop()



now time to add data collection functionality, collect() is designed to collect data from username and password entry widget


#program

try:
from Tkinter import *
except:
from tkinter import *

def collect():
a = u_en.get()
b = p_en.get()
print("username:", a, "\nPassword", b)


mw = Tk()

mw.geometry(
"600x100+50+50")
mw.title(
"AETies : Automation Expert Technologies")
mw.config(
background='#eeeeee')

f1 = Frame(mw
, bg='#eeeeee')
f1.pack()

l1 = Label(f1
, text=' Username :\t', bg='#eeeeee').pack(side=LEFT)
u_en = Entry(f1
, width=20)
u_en.pack(
side=LEFT)

f2 = Frame(mw
, bg='#eeeeee')
f2.pack()
l2 = Label(f2
, text=' Password :\t', bg='#eeeeee').pack(side=LEFT)
p_en = Entry(f2
, width=20)
p_en.pack(
side=LEFT)

btn = Button(mw
, text=' Login ', command=collect).pack()

mainloop()

 #output

username: mandeep.singh
password: aeties





Comments

My photo
Techno Xpresss
Bangalore, Karnataka, India