Tkinter ttk radiobutton variable update failure
<p>What's wrong with this?</p>

<pre><code>var = StringVar()
radBut1 = ttk.Radiobutton(root, text='A - Z', variable=var, value='AtoZ')
radBut2= ttk.Radiobutton(root, text='Z - A', variable=var, value='ZtoA')
</code></pre>

<p>When I select either of the 2 radiobuttons, the var variable is not updated. I found a lot of conflicting material in different documentation sources and tutorials (and I tried everything I found) to no avail.</p>

<p>I'm using the following to check the value of var:</p>

<pre><code>print(var)
</code></pre>

<p>This works:</p>

<pre><code>def updateRadioButtonVariable(radioButtonVar,updateString):
    radioButtonVar.set(updateString)

#Sort Type Radio Button
radioButtonVar = StringVar()
radBut1= ttk.Radiobutton(root, text='A - Z', variable=radioButtonVar, value='AtoZ',command= lambda: updateRadioButtonVariable(radioButtonVar ,'AtoZ'))
radBut2= ttk.Radiobutton(root, text='Z - A', variable=radioButtonVar, value='ZtoA',command= lambda: updateRadioButtonVariable(radioButtonVar ,'ZtoA'))
</code></pre>

<p>Not sure why the original code (which is almost template code from the documentation) doesn't work. If anyone has any ideas, please do share.</p>

python tkinter radio-button ttk