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
#2
You can attach a "command=" to the radiobutton which would make a status button unnecessary. You can insert the appropriate text based on the number of the button clicked. An example from my toolbox.
import tkinter

class CrudGUI:
    def __init__(self, master):
        self.master = master

        self.radio_var = tkinter.IntVar()
        self.radio_var.set(1)

        # create radio buttons

        self.look = tkinter.Radiobutton(self.master, text="Look up customer",
                                        variable=self.radio_var, value=1,
                                        command=self.open_menu)
        self.add = tkinter.Radiobutton(self.master, text="Add a customer",
                                       variable=self.radio_var, value=2,
                                       command=self.open_menu)
        self.change = tkinter.Radiobutton(self.master, text="Change customer information",
                                       variable=self.radio_var, value=3,
                                       command=self.open_menu)
        self.delete = tkinter.Radiobutton(self.master, text="Delete a customer",
                                          variable=self.radio_var, value=4,
                                          command=self.open_menu)

        # pack radio buttons

        self.look.pack(anchor='w', padx=20)
        self.add.pack(anchor='w', padx=20)
        self.change.pack(anchor='w', padx=20)
        self.delete.pack(anchor='w', padx=20)

        self.quit_button = tkinter.Button(self.master, text="QUIT",
                           command=self.master.quit, bg="orange")
        self.quit_button.pack(side='left', expand="yes")

    def open_menu(self):
        print(self.radio_var.get())

root=tkinter.Tk()
VF=CrudGUI(root)
root.mainloop()
Reply


Messages In This Thread
RE: Clicking a RadioButton in a for Loop & Getting the Appropriate Return - by woooee - Feb-02-2019, 01:53 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Clicking on the button crashes the TK window ODOshmockenberg 1 2,258 Mar-10-2022, 05:18 PM
Last Post: deanhystad
  How to dynamically change radiobutton text kenwatts275 2 3,377 Mar-05-2021, 02:25 AM
Last Post: deanhystad
  Python3 tkinter radiobutton problem Nick_tkinter 14 6,093 Feb-15-2021, 11:01 PM
Last Post: Nick_tkinter
  [Tkinter] RadioButton Maryan 2 2,189 Oct-23-2020, 09:36 PM
Last Post: Maryan
  [Tkinter] How to create radiobutton in numpy gui python? luthfidali 2 2,624 May-23-2020, 10:35 AM
Last Post: timo
  Tkinter: increasing numbers and Radiobutton issue PeroPuri 1 2,178 Apr-13-2020, 05:48 PM
Last Post: deanhystad
  Need tkinter help with clicking buttons pythonprogrammer 2 2,482 Jan-03-2020, 04:43 AM
Last Post: joe_momma
  [PyQt] how to deselect radiobutton in pyqt5 atlass218 3 12,791 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 4,730 May-27-2019, 04:24 PM
Last Post: Yoriz
  [Tkinter] Adding New TAB to NoteBook Widget by Clicking Vicolas 0 2,628 Feb-15-2019, 06:03 PM
Last Post: Vicolas

Forum Jump:

User Panel Messages

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