title: Why is both radio buttons selected in tkinter when the program starts?
body: <p>I am new to Tkinter buttons and radio buttons widgets. I have been given this python code that was given by my lab instructor. The code basically uses Tkinter and prints the value of a selected radio buttons value. But the problem is when I run the program It shows that both radio buttons are selected. How can I solve this issue? the code is given below</p>
  <pre><code>import tkinter as tk
  
  window = tk.Tk()
  window.title('Programming for Data Science')
  # width x height + x_offset + y_offset:
  window.geometry(&quot;500x250+100+100&quot;)
  
  # Set font
  myFont = &quot;Arial, 16&quot;
  # Add a label
  lbl_header = tk.Label(text=&quot;A Simple GUI App&quot;, font=myFont, height=1)
  lbl_header.place(x=150, y=10)
  # Add label
  lbl = tk.Label(text=&quot;Select a colour: &quot;, fg=&quot;navy&quot;, anchor=&quot;w&quot;, width=25, height=1, font=myFont)
  lbl.place(x=10, y=50)
  # Add variable var and 2 radio buttons
  var = tk.StringVar()
  rb1 = tk.Radiobutton(text=&quot;red&quot;, variable=var, value='r', font=myFont)
  rb1.place(x=180, y=50)
  rb1.deselect()
  
  rb2 = tk.Radiobutton(text=&quot;blue&quot;, variable=var, value='b', font=myFont)
  rb2.place(x=250, y=50)
  rb2.deselect()
  # Label to display output when button is clicked
  lb_output = tk.Label(text=&quot;&quot;, fg=&quot;navy&quot;, anchor=&quot;w&quot;, width=25, height=1, font=myFont)
  lb_output.place(x=10, y=100)
  
  
  #################################
  
  def select_item():
      selected = var.get()
      if selected == 'r':
          output = 'Red selected'
      elif selected == 'b':
          output = 'Blue selected'
      else:
          output = &quot;Please select a colour&quot;
  
      lb_output.config(text=output)
  #################################
  
  
  # Add button
  button = tk.Button(text=&quot;Run&quot;, fg=&quot;black&quot;, bg=&quot;lightblue&quot;, width=10, height=1, font=myFont, command=select_item)
  button.place(x=10, y=150)
  
  window.mainloop()
  </code></pre>