Issues accessing Tkinter Radio Button CTRL var
<p>I am having trouble getting the value of the selected radio button. Currently when I use the <code>.get()</code> function on my varible that the radio buttons use it returns "" nothing. If I use the message box without the <code>.get()</code> function then it returns <code>PY_VAR</code>x where x is the specific instance of the tkinter variable.</p>

<p>The radio buttons are using the variable properly, as seen by the fact that you can only select one radio button at a time, but I am not able to read the value properly. I want to read the current selection and put it into a different variable.</p>

<p>Below is abridged code (you are only seeing the radio button part of the program).</p>

<pre><code>from tkinter import *
from tkinter import messagebox, ttk

class init_system:
    def __init__(self):
        self.init_vars = {"w_audiocodec": "Windows Media Audio 9.2 Lossless"}

class render_window:
    def __init__(self, height, width, window_title):
        self.root_window = Tk()
        w = width
        h = height
        ws = self.root_window.winfo_screenwidth() # width of the screen
        hs = self.root_window.winfo_screenheight() # height of the screen
        x = (ws/2) - (w/2)
        y = (hs/2) - (h/2)
        self.root_window.title(window_title)
        self.root_window.minsize(width, height)
        self.root_window.geometry('%dx%d+%d+%d' % (w, h, x, y))
        self.master_dictionary = {"radio_ctrl": StringVar()}

    def new_button(self, button_text, button_command="", grid_row=0, grid_column=0, grid_sticky="NESW", grid_columnspan=1, grid_rowspan=1):
        self.button = ttk.Button(self.root_window, text=button_text, command=button_command)
        self.button.grid(row=grid_row, column=grid_column, sticky=grid_sticky, columnspan=grid_columnspan, rowspan=grid_rowspan)
        self.responsive_grid(grid_row, grid_column)

    def new_label(self, label_text, text_alignment="center", grid_row=0, grid_column=0, grid_sticky="NESW", grid_columnspan=1, grid_rowspan=1):
        self.label = ttk.Label(self.root_window, text=label_text, anchor=text_alignment)
        self.label.grid(row=grid_row, column=grid_column, sticky=grid_sticky, columnspan=grid_columnspan, rowspan=grid_rowspan)
        self.responsive_grid(grid_row, grid_column)

    def responsive_grid(self, row_responsive=0, column_responsive=0, row_weight_num=1, column_weight_num=1):
        self.root_window.grid_columnconfigure(column_responsive, weight=column_weight_num)
        self.root_window.grid_rowconfigure(row_responsive, weight=row_weight_num)

    def new_radio_button(self, widget_text="Radio Button", radio_value="Radio Btn", radio_command="", grid_row=0, grid_column=0, grid_sticky="NESW", grid_columnspan=1, grid_rowspan=1):
        self.radio_button = ttk.Radiobutton(self.root_window, text=widget_text, variable=self.master_dictionary["radio_ctrl"], value=radio_value, command=radio_command)
        self.radio_button.grid(row=grid_row, column=grid_column, sticky=grid_sticky, columnspan=grid_columnspan, rowspan=grid_rowspan)
        self.responsive_grid(grid_row, grid_column)

class change_var_window(render_window):

    change_var_window_values = {"example_data_below": "Check it out!",
    "var_to_change": "show_ui",
    "toggle": False,
    "radio": False,
    "free_form":False,
    "line_one": "Current value of:",
    "line_two": "some varible name here passwed with a dicrionary",
    "Custom_Data_Bool": False,
    "Custom_Disable": "Enable me",
    "Custom_Enable": "Disable me",
    "radio_list": [("Radio Button 1", "btn_1"), ("Radio Button 2", "btn_2"), ("Radio Button 3", "btn_3")],
    "is_number": True}

    def save_radio_var(self):
        vars_system.init_vars[self.change_var_window_values["var_to_change"]] = self.master_dictionary["radio_ctrl"].get()
        messagebox.showinfo("debug", self.master_dictionary["radio_ctrl"].get()) 

    def create_change_var_window(self):
        self.new_label(self.change_var_window_values["line_one"], grid_columnspan=2)
        self.new_label(self.change_var_window_values["line_two"], grid_row=1, grid_columnspan=2)
        if self.change_var_window_values["radio"]:
            grid_placement = 2
            self.master_dictionary["radio_ctrl"] = StringVar()
            #self.master_dictionary["radio_ctrl"].set(vars_system.init_vars[self.change_var_window_values["var_to_change"]])
            for radio_name, value in self.change_var_window_values["radio_list"]:
                self.new_radio_button(widget_text=radio_name, radio_value=value, grid_row=grid_placement)
                grid_placement +=1
            grid_placement -=1
            self.new_button("Cancle", self.root_window.destroy, grid_row=grid_placement, grid_column=1)
            grid_placement -=1
            self.new_button("Save", self.save_radio_var, grid_row=grid_placement, grid_column=1)
            # Radio Requires:
            # "radio_list" "var_to_change"
        self.root_window.mainloop()

def radio_example():
    radio = change_var_window(300, 350, "Radio Select")
    radio.change_var_window_values.update({"free_form": False, "toggle": False, "radio": True, "var_to_change": "w_audiocodec", "line_one": "Current value of w_audiocodec:", "line_two": vars_system.init_vars["w_audiocodec"]})
    radio.change_var_window_values.update({"radio_list": [("Windows Media Audio 9.2", "Windows Media Audio 9.2"), ("Windows Media Audio 9.2 Lossless", "Windows Media Audio 9.2 Lossless"), ("Windows Media Audio 10 Professional", "Windows Media Audio 10 Professional")]})
    #main_window.root_window.withdraw()
    radio.create_change_var_window()

vars_system = init_system()

main_window = render_window(200, 250, "Main Window")
main_window.new_button("Radio Var", radio_example)

main_window.root_window.mainloop()
</code></pre>

<p>Thank you for taking time to look at this issue :-)</p>

<p>The problem is related to the fact that you are creating more than one root window. You need to change your code so that you create exactly one instance of <code>Tk</code> for the life of your program.  Widgets and variables in one root cannot be shared with widgets and variables from another root window. </p>

<p>If you need more than one window, all but the root window need to be instances of <code>Toplevel</code>. </p>

python python-3.x variables tkinter radio-button