As suggested over here, I have created a separate class, exclusively for Tkinter. The main function just gets the scale values from the Tkinter GUI. Though I'm able to get these scale values, I am unable to exit the program after closing the GUI. My program just seems to be stuck after self.root.mainloop()
i.e print "mainloop"
gets executed. I do not have any problems in terminating the script, if I do something as follows, i.e, if I do not access the output_q
values
i = 0
while app.run:
print i
i = i+1
The entire code is given below
from Tkinter import *
import threading, time, sys, Queue
class App(threading.Thread):
def __init__(self, var):
threading.Thread.__init__(self)
self.output_q = Queue.Queue()
self.start()
def callback(self):
self.run = 0
self.root.quit()
self.root.destroy()
def pub_y(self, val_y):
self.x_val = float(self.y_scale.get())
self.output_q.put((self.x_val, 2, 3))
def run(self):
self.root = Tk()
self.root.protocol("WM_DELETE_WINDOW", self.callback)
self.y_var = DoubleVar()
self.y_scale = Scale( self.root, from_=0, to=1, length=300, label="yaw", resolution=0.0000000000001, variable = self.y_var, orient=HORIZONTAL, command=self.pub_y)
self.y_scale.set(0.5)
self.y_scale.pack(anchor=CENTER)
label = Label(self.root, text="Hello World")
label.pack()
self.root.mainloop()
print "mainloop"
var = 1
input = Queue.Queue()
input.put((1,2,3))
app = App(input)
i = 0
while app.run:
result = app.output_q.get()
print result[0]
sys.exit(0)
Could someone point out where I might be going wrong? Thanks!