I want to retrieve and show the values in this basic python GUI form. how to retrieve the radiobutton and checkbox values and display it? Here's Code

siddxx18
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()
HackerAnnan

Output

Input

The Whole Code:

from tkinter import *
from tkinter import Button, Entry, Label, messagebox, ttk

top = Tk()
top.geometry("400x600")

def submit():
    namevar = e1.get()
    emailvar = e2.get()
    phonevar = e3.get()

    gen1=genSelect()

    if CheckVar1.get() == 1:
        h1 = 'Sports'
    else:
        h1 = ''
    if CheckVar2.get() == 1:
        h2 = 'Music'
    else:
        h2= ''
    if CheckVar3.get() == 1:
        h3 = 'Cooking'
    else:
        h3 = ''
    if CheckVar4.get() == 1:
        h4 = 'Reading Books'
    else:
        h4 = ''
    if CheckVar5.get() == 1:
        h5 = 'Gaming'
    else:
        h5 = ''

    con=country.get()
    for i in states.curselection():
        state = states.get(i)
        print(state)
        
    # st=states.get()
    messagebox.showinfo("Your details", "Your Name is: "+namevar+"\n Email: "+emailvar+"\n Phone: "+str(phonevar)+"\n Gender: "+gen1+
                        "\n Hobbys: "+h1+","+h2+","+h3+","+h4+","+h5+"\n Country: "+con+"\n State"+state)
                        
var = IntVar()
CheckVar1 = IntVar()
CheckVar2 = IntVar()
CheckVar3 = IntVar()
CheckVar4 = IntVar()
CheckVar5 = IntVar()

def genSelect():
    choice = var.get()
    if choice == 1:
        gen = "Male"

    elif choice == 2:
        gen = "Female"
    else:
        gen = "Invalid selection"
        
    return gen
    
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)

Checkbutton(lb2, text="Sports", variable=CheckVar1, onvalue=1, offvalue=0).place(x=5, y=12)
Checkbutton(lb2, text="Music", variable=CheckVar2, onvalue=1, offvalue=0).place(x=80, y=12)
Checkbutton(lb2, text="Cooking", variable=CheckVar3, onvalue=1, offvalue=0).place(x=155, y=12)
Checkbutton(lb2, text="Reading Books", variable=CheckVar4, onvalue=1, offvalue=0).place(x=230, y=12)
Checkbutton(lb2, text="Gaming", variable=CheckVar5, onvalue=1, offvalue=0).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()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to retrieve checked values

How to retrieve nested map values

How to retrieve form values from HTTPPOST, dictionary or?

How to retrieve checkboxes values in jQuery

How to get urwid RadioButton and CheckBox values?

How do I save multiple checkbox values in a single column in the database and retrieve it using laravel

How to display rounded values in a form and show on focus the original values?

How to retrieve values from drop down when select tag style attribute is set as display: none; in python selenium

How to retrieve the column values in codeigniter?

In Redux, how to retrieve values from an API and show the result in the component

How to retrieve values using XmlService?

How to retrieve/know function's default values

localStorage - Retrieve Checkbox Values

Retrieve values of excel as python dictionary

I want to get checkbox values

I want to display parts of the form according to the how the user selects the checkbox

I want to retrieve values from my JButton extension

How to retrieve values from this object

Retrieve css tag values in python

How do i retrieve values (Message) and (Code) from the reply of twitter api?

How to retrieve values of multiple txtBoxes and display sum in a new page?

How to retrieve form values from a React.FormEvent<HTMLFormElement>?

Retrieve values from TransientModel in Python

How to retrieve the values of "Total"

How to correctly retrieve and display JSON object values in datatable in ReactJS?

How do I save multiple checkbox values in a single column separately in the database and retrieve it using laravel?

I want to display a dynamic form only when there are values for that id as below?How can i approach it?

I want to retrieve data in Python

how to retrieve dictionary's unquoted values