Aug-06-2019, 03:05 AM
(This post was last modified: Aug-06-2019, 03:08 AM by cpssunnychan.)
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!