Header Ads

Responsive Ads Here

User form form using Tkinter Python

 User Info Form


from tkinter import *

win = Tk()

win.title("Form")
win.configure(background="#94ebe9")

name_l = Label(win, text="Name:")
name_l.grid(row=0, column=0, sticky=W)
name_l.configure(foreground="red", background="#94ebe9")

name_val = StringVar()
name_e = Entry(win, width=18, textvariable= name_val)
name_e.grid(row=0, column=1, sticky=W)
name_e.configure(foreground="blue", background="#b8e681")

age_l = Label(win, text="Age:")
age_l.grid(row=1, column=0, sticky=W)
age_l.configure(foreground="red", background="#94ebe9")

age_val = IntVar()
age_e = Entry(win, width=18, textvariable= age_val)
age_e.grid(row=1, column=1, sticky=W)
age_e.configure(foreground="blue", background="#b8e681")

email_l = Label(win, text="E-mail:")
email_l.grid(row=2, column=0, sticky=W)
email_l.configure(foreground="red", background="#94ebe9")

email_val = StringVar()
email_e = Entry(win, width=18, textvariable= email_val)
email_e.grid(row=2, column=1, sticky=W)
email_e.configure(foreground="blue", background="#b8e681")

gender_l = Label(win, text="Gender:")
gender_l.grid(row=3, column=0, sticky=W)
gender_l.configure(foreground="red", background="#94ebe9")

radio_var = StringVar()

radio1 = Radiobutton(win, text="Male", value="male", variable= radio_var)
radio2 = Radiobutton(win, text="Female", value="female", variable= radio_var)
radio3 = Radiobutton(win, text="Other", value="other", variable= radio_var)

radio1.grid(row=3, column=1, sticky=W)
radio2.grid(row=3, column=2, sticky=W)
radio3.grid(row=3, column=3, sticky=W)

radio1.configure(foreground="red", background="#94ebe9")
radio2.configure(foreground="red", background="#94ebe9")
radio3.configure(foreground="red", background="#94ebe9")

check_val = IntVar()
check = Checkbutton(win, text="I liked the app!!", variable=check_val)
check.grid(row=4, column=0)
check.configure(foreground="red", background="#94ebe9")


def Get_val():
    print(f"Name: {name_val.get()}")
    print(f"Age: {age_val.get()}")
    print(f"E_mail: {email_val.get()}")
    print(f"Gender: {radio_var.get()}")

    if check_val.get() == 0:
        print(f"{name_val.get()} did not liked the app!!")
    else:
        print(f"{name_val.get()} liked the app!!")



button = Button(win, text="Submit", command= Get_val)
button.grid(row=5, column=0)
button.configure(foreground="#191ce0", background="#d9e31b")
win.mainloop()


Output




YouTube Video: https://www.youtube.com/watch?v=Gs4SXdartuA



Powered by Blogger.