from tkinter import *
from tkinter import Button, Entry, Label, messagebox, ttk
top = Tk()
top.geometry("400x600")
here it does not retrieve the gender and check box values. How do i get the radiobutton values from another function named genSelect()?
def submit():
namevar = e1.get()
emailvar = e2.get()
phonevar = e3.get()
gen1=print(genSelect.gen)
h1=c1.get()
h2=c2.get()
h3=c3.get()
h4=c4.get()
h5=c5.get()
con=country.get()
st=states.get()
messagebox.showinfo("Your details", "Your Name is: "+namevar+"\n Email: "+emailvar+"\n Phone: "+phonevar+"\n Gender: "+gen1+
"\n Hobbys: "+h1+","+h2+","+h3+","+h4+","+h5+"\n Country: "+con+"\n State"+st)
I created another function to get the gender values. SHould i do the same to get the values for Checkbox?
def genSelect():
choice = var.get()
if choice == 1:
genSelect.gen = "Female"
elif choice == 2:
genSelect.gen = "Female"
else:
genSelect.gen = "Invalid selection"
#This is for The form spread over 3 sections. bhdgchnxmiq,ijsjqijxiaihuxhwjxnwjx
var = IntVar()
CheckVar1 = IntVar()
CheckVar2 = IntVar()
CheckVar3 = IntVar()
CheckVar4 = IntVar()
CheckVar5 = IntVar()
register = Label(top, text="Register Form", font={})
register.place(x=120, y=5)
lb1 = LabelFrame(top, text="Personal Details")
lb1.place(height=160, width=390, x=5, y=35)
name = Label(lb1, text="Name")
name.place(x=50, y=20)
email = Label(lb1, text="Email")
email.place(x=50, y=50)
phone = Label(lb1, text="Phone no.")
phone.place(x=50, y=80)
gender = Label(lb1, text="Gender")
gender.place(x=50, y=110)
e1 = Entry(lb1)
e1.place(x=120, y=20)
e2 = Entry(lb1)
e2.place(x=120, y=50)
e3 = Entry(lb1)
e3.place(x=120, y=80)
R1 = Radiobutton(lb1, text="Male", variable="var", value="1")
R1.place(x=120, y=110)
R2 = Radiobutton(lb1, text="Female", variable="var", value="2")
R2.place(x=180, y=110)
lb2 = LabelFrame(top, text="Hobby")
lb2.place(height=70, width=390, x=5, y=200)
c1 = Checkbutton(lb2, text="Sports", variable=CheckVar1, onvalue=1, offvalue=0)
c1.place(x=5, y=12)
c2 = Checkbutton(lb2, text="Music", variable=CheckVar2, onvalue=1, offvalue=0)
c2.place(x=80, y=12)
c3 = Checkbutton(lb2, text="Cooking", variable=CheckVar3, onvalue=1, offvalue=0)
c3.place(x=155, y=12)
c4 = Checkbutton(lb2, text="Reading Books", variable=CheckVar4, onvalue=1, offvalue=0)
c4.place(x=230, y=12)
c5 = Checkbutton(lb2, text="Gaming", variable=CheckVar5, onvalue=1, offvalue=0)
c5.place(x=305, y=12)
lb3 = LabelFrame(top, text="Address")
lb3.place(height=205, width=390, x=5, y=277)
country_name = Label(lb3, text="Country")
country_name.place(x=10, y=8)
state_name = Label(lb3, text="State")
state_name.place(x=10, y=38)
country = ttk.Combobox(lb3, values=
[
"INDIA",
"Australia",
"Russia",
"Egypt",
"U.S.A",
"Canada",
"Argentina"
])
country.current(0)
country.place(x=65, y=8)
states = Listbox(lb3, selectmode=SINGLE, height=8, width=20)
states.insert(1, "Maharashtra")
states.insert(2, "Madhya Pradesh")
states.insert(3, "Kerala")
states.insert(4, "Orissa")
states.insert(5, "Punjab")
states.insert(6, "Rajast`enter code here`han")
states.insert(7, "Assam")
states.insert(8, "Gujarat")
states.place(x=65, y=42)
b1 = Button(top, command=submit, text="Submit", font={"arial", 12}, relief="solid")
b1.place(x=150, y=520)
top.mainloop()
Aucun commentaire:
Enregistrer un commentaire