0
通过修改一些在Stackoverflow中的答案中存在的代码(抱歉,我不记得它是哪一个),下面是代码片段。 我试图通过使用tkinter scale
来改善它。Tkinter实时比例
#!/usr/bin/env python
from Tkinter import *
import threading
class MyTkApp(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.start()
def callback(self):
self.root.quit()
def show_values(self):
print self.s2.get()
print self.s1.get()
def run(self):
self.root=Tk()
self.root.protocol("WM_DELETE_WINDOW", self.callback)
self.s1 = Scale(self.root, from_=0, to=42, tickinterval=8)
self.s1.set(19)
self.s1.pack()
self.s1.get()
self.s2 = Scale(self.root, from_=0, to=200, length=600,tickinterval=10, orient=HORIZONTAL)
self.s2.set(23)
self.s2.pack()
Button(self.root, text='Show', command=self.show_values).pack()
self.root.mainloop()
app = MyTkApp()
print app.show_values()
for a in range(0,10):
print 'now can continue running code while mainloop runs'
我正在尝试获取值并将其返回到主循环的其余部分。 我们如何实现这一目标?
有回调的问题是,直到'scale'关闭程序的其余部分无法继续执行。 – pistal
@pistal,如何在线程中运行程序**的其余部分? – falsetru
“程序的其余部分”已经写入,没有线程,并且改变该部分看起来不太可行。 在这里找到了一些东西:'http:// stackoverflow.com/questions/17257045 /试图从tkinter中获得价值 - 将它放入标签中' Still搞清楚如何实现它 – pistal