Python Forum
[Tkinter] Clicking a RadioButton in a for Loop & Getting the Appropriate Return
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Clicking a RadioButton in a for Loop & Getting the Appropriate Return
#1
from tkinter import *
root = Tk()
root.title('Register')

def status():
    word = varr.get()
    gender = var.get()
    if gender == 1:
        text.insert(END,f'Hi Mr {word}\nHow are you doing today?')
    else:
        text.insert(END, f'Hi Miss {word}\nHow are you doing today?')

varr = StringVar()
entryfield = Pmw.EntryField(root,labelpos=W,label_text='Name:',entry_width=22,entry_textvariable=varr)
entryfield.grid(row=0,column=0,sticky=W,padx=5,pady=5)

button = Button(root,text='Status',command=status)
button.grid(row=0,column=0,sticky=E,padx=5,pady=5,ipadx=10)

var = IntVar()
f = Frame(root)
f.grid()
for i,k,j in [('Male',1,0),('Female',1,1)]:
    radiobutton = Radiobutton(f,text=i,variable=var,value=i,indicatoron=0)
    radiobutton.grid(row=k,column=j,sticky=W,padx=5,pady=5,ipadx=30)
frame = Frame(root)
frame.grid()
text = Text(frame,width=30,height=5)
text.grid(row=2,column=0,padx=5,pady=5)
root.mainloop()
Please, how can I click on either of the RadioButtons and then the 'Status' Button and get the appropriate text inserted into my Text widget.
I tried doing it but I got this error: _tkinter.TclError: expected floating-point number but got "Male".
Thanks.
Reply


Messages In This Thread
Clicking a RadioButton in a for Loop & Getting the Appropriate Return - by Vicolas - Feb-02-2019, 12:08 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to dynamically change radiobutton text kenwatts275 2 4,641 Mar-05-2021, 02:25 AM
Last Post: deanhystad
  Python3 tkinter radiobutton problem Nick_tkinter 14 9,778 Feb-15-2021, 11:01 PM
Last Post: Nick_tkinter
  [Tkinter] RadioButton Maryan 2 2,908 Oct-23-2020, 09:36 PM
Last Post: Maryan
  [Tkinter] How to create radiobutton in numpy gui python? luthfidali 2 3,281 May-23-2020, 10:35 AM
Last Post: timo
  Tkinter: increasing numbers and Radiobutton issue PeroPuri 1 2,934 Apr-13-2020, 05:48 PM
Last Post: deanhystad
  Need tkinter help with clicking buttons pythonprogrammer 2 3,463 Jan-03-2020, 04:43 AM
Last Post: joe_momma
  [PyQt] how to deselect radiobutton in pyqt5 atlass218 3 15,870 Oct-23-2019, 03:25 PM
Last Post: Denni
  [Tkinter] RE: status bar to return to the centre after 1 minute of clicking a button ? chano 6 6,341 May-27-2019, 04:24 PM
Last Post: Yoriz
  [Tkinter] Radiobutton in Tkinter not Updating Variable from Value Aidan54321 1 8,500 Jun-16-2017, 11:08 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020