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