Python Forum
[Tkinter] Ratiobutton default value in a function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Ratiobutton default value in a function
#1
I want to add a radiobutton that have a default value on my gui (switching between 'digital' and 'analog'). Therefore, I added the following lines

    tk.Label(root, text = 'MPD').grid(row = 1, column = 15)
    MPDmode = tk.Frame(root)
    MPDmode.grid(row = 2, column = 15)
    MPDmode_var = tk.StringVar(value = 'digital')
    MPDdigital = tk.Radiobutton(MPDmode, text = 'Digital', variable = MPDmode_var, indicatoron = False, value = 'digital', width = 8)
    MPDanalog = tk.Radiobutton(MPDmode, text = 'Analog', variable = MPDmode_var, indicatoron = False, value = 'analog', width = 8)
    MPDdigital.grid(row = 0)
    MPDanalog.grid(row = 1)
When I run this individually, it works well. However, if I define the above in a function.

def startGUI():
'''The above stuff'''
and run it as
root = tk.Tk()
startGUI()
root.mainloop()
The radiobutton takes nothing as the default value. I wonder how I can solve it, thanks!
Reply


Messages In This Thread
Ratiobutton default value in a function - by cpssunnychan - Aug-06-2019, 03:05 AM

Forum Jump:

User Panel Messages

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