title: Restart script on button press using tkinter
body: <p>I have a simple script to convert Degree Minute Second to Decimal Degree, using tkinter with a simple GUI. The script waits for the user to click the &quot;Calculate&quot; button before proceeding, to ensure values have been entered in the required 'tk.Entry' fields, then displays the calcuated output.</p>
  <p>How would I implement a &quot;Reset&quot; button to allow for another calculation to be run?</p>
  <p>I was thinking a while loop for my entire script but don't understand how to implement it.</p>
  <p>Apologies for the elementary question, this is my first attempt at using tkinter / GUI, it was much easier to add a re-run while loop to the commandline version of my script.</p>
  <p>edit: the &quot;Reset&quot; button currently does nothing, it's just for placement.</p>
  <pre><code># Check python version and import correct tkinter.
  import string
  import sys
  if (sys.version_info.major == 3):
      print(&quot;Python 3&quot;)
      import tkinter as tk# for Python 3
  else:
      print(&quot;Python 2&quot;)
      import Tkinter as tk# for Python 2.7
  
  # Configure tkinter window name, size, colour, columns.
  root = tk.Tk()
  root.title(&quot;CCT&quot;)
  root.resizable(False, False)
  root.attributes(&quot;-alpha&quot;, 0.95)
  root.config(bg = &quot;#F5F5F5&quot;)
  
  # Label for top of application.
  label_info = tk.Label(root, text=&quot;Coordinate Conversion Tool&quot;, pady = 5, bg = &quot;#e8e8e8&quot;, padx=10)
  label_info.grid(row=0, column=0, columnspan=4, sticky = tk.W+tk.E, pady=(0,10))
  
  # Label and entry for degree.
  label_d = tk.Label(text=&quot;Degree -&gt;&quot;, bg = &quot;#F5F5F5&quot;)
  label_d.grid(row=1, column=0, columnspan=2, sticky = tk.W, padx=(10,0))
  entry_d = tk.Entry(root, width=10, bg = &quot;#e8e8e8&quot;)
  entry_d.grid(row=1, column=2, columnspan=2, sticky = tk.E, padx=(0,10))
  
  # Label and entry for minute.
  label_m = tk.Label(text=&quot;Minute -&gt;&quot;, bg = &quot;#F5F5F5&quot;)
  label_m.grid(row=2, column=0, columnspan=2, sticky = tk.W, padx=(10,0))
  entry_m = tk.Entry(root, width=10, bg = &quot;#e8e8e8&quot;)
  entry_m.grid(row=2, column=2, columnspan=2, sticky = tk.E, padx=(0,10))
  
  # Label and entry for second.
  label_s = tk.Label(text=&quot;Second -&gt;&quot;, bg = &quot;#F5F5F5&quot;)
  label_s.grid(row=3, column=0, columnspan=2, sticky = tk.W, padx=(10,0))
  entry_s = tk.Entry(root, width=10, bg = &quot;#e8e8e8&quot;)
  entry_s.grid(row=3, column=2, columnspan=2, sticky = tk.E, padx=(0,10))
  
  # Radiobutton for quadrant selection.
  def retrieve():
      print(quadrant_var.get())
  
  quadrant_var = tk.StringVar(value = &quot;N&quot;)
      
  quad_button_n = tk.Radiobutton(root, text = &quot;N&quot;, variable = quadrant_var, value = &quot;N&quot;, command = retrieve, pady = 3)
  quad_button_n.grid(row=4, column=0)
      
  quad_button_e = tk.Radiobutton(root, text = &quot;E&quot;, variable = quadrant_var, value = &quot;E&quot;, command = retrieve, pady = 3)
  quad_button_e.grid(row=4, column=1)
  
  quad_button_s = tk.Radiobutton(root, text = &quot;S&quot;, variable = quadrant_var, value = &quot;S&quot;, command = retrieve, pady = 3)
  quad_button_s.grid(row=4, column=2)
  
  quad_button_w = tk.Radiobutton(root, text = &quot;W&quot;, variable = quadrant_var, value = &quot;W&quot;, command = retrieve, pady = 3)
  quad_button_w.grid(row=4, column=3)
  
  # Set blank variable for wait_variable
  var = tk.IntVar()
  
  # Button for calculating the conversion with wait_variable
  calculate = tk.Button(text=&quot;Calculate&quot;, command=lambda: var.set(1))
  calculate.grid(row=5, column=0, columnspan=2, sticky = tk.E+tk.W, padx=10, pady=10)
  
  # Button to reset and allow for another calculation
  calculate = tk.Button(text=&quot;Reset&quot;)
  calculate.grid(row=5, column=2, columnspan=2, sticky = tk.E+tk.W, padx=10, pady=10)
  
  # Label with placeohlder output text
  label_output = tk.Label(text=&quot; &quot;, borderwidth=2, relief=&quot;groove&quot;, font=&quot;Arial, 12&quot;, pady=8)
  label_output.grid(row=7, column=0, columnspan=4, sticky = tk.W+tk.E, padx=10)
  
  # Label at the bottom of the application
  label_foot = tk.Label(text=&quot;Developed by Ryan Seabrook&quot;, bg = &quot;#F5F5F5&quot;, fg = &quot;#7a7a7a&quot;, pady = 1)
  label_foot.grid(row=8, column=0, columnspan=4, sticky = tk.W+tk.E)
  
  # Wait for the user to press the calculate button.
  calculate.wait_variable(var)
  
  # Information from user input for degree minute second, converted to float for math calculation.
  degree = float(entry_d.get())
  minute = float(entry_m.get())
  second = float(entry_s.get())
  
  # Raw calculated output for DMS to DD.
  calculated_dd = (float(degree) + (float(minute)/60) + (float(second)/3600))
  
  # Rounded DD output.
  rounded_dd = round(calculated_dd,8)
  
  # Fetch string for final output
  rounded_dd_str = str(rounded_dd)
  final_output = &quot;output&quot;
  selected_quadrant = quadrant_var.get()
  
  # If statement to assign correct quadrant value to output
  if selected_quadrant == &quot;W&quot;:
      final_output = &quot;-&quot; + rounded_dd_str + &quot; &quot; + selected_quadrant
  elif selected_quadrant == &quot;S&quot;:
      final_output = &quot;-&quot; + rounded_dd_str + &quot; &quot; + selected_quadrant
  else:
      final_output = rounded_dd_str + &quot; &quot; + selected_quadrant
  
  # Label for final output
  label_output = tk.Label(text=final_output, borderwidth=2, relief=&quot;sunken&quot;, font=&quot;Arial 12&quot;, pady=8)
  label_output.grid(row=7, column=0, columnspan=4, sticky = tk.W+tk.E, padx=10)
  
  # Holds python while tkinter root window is open.
  root.mainloop()
  </code></pre>