我正在做一個基本的GUI,以便在某些shell命令之後提供一些用戶反饋,真的是一個shell腳本的小接口。使用Python進行shell命令的基本GUI Tk線程和os.system調用
顯示一個TK窗口,在每個os.system調用之後等待os.system調用完成並更新TK窗口多次。
線程如何與tk一起工作?
就是這樣,謝謝!
我正在做一個基本的GUI,以便在某些shell命令之後提供一些用戶反饋,真的是一個shell腳本的小接口。使用Python進行shell命令的基本GUI Tk線程和os.system調用
顯示一個TK窗口,在每個os.system調用之後等待os.system調用完成並更新TK窗口多次。
線程如何與tk一起工作?
就是這樣,謝謝!
只是我做了什麼的一個基本例子,因爲指望Constantinius指出Thread與Tk一起工作!
import sys, thread
from Tkinter import *
from os import system as run
from time import sleep
r = Tk()
r.title('Remote Support')
t = StringVar()
t.set('Completing Remote Support Initalisation ')
l = Label(r, textvariable=t).pack()
def quit():
#do cleanup if any
r.destroy()
but = Button(r, text='Stop Remote Support', command=quit)
but.pack(side=LEFT)
def d():
sleep(2)
t.set('Completing Remote Support Initalisation, downloading, please wait ')
run('sleep 5') #test shell command
t.set('Preparing to run download, please wait ')
run('sleep 5')
t.set("OK thanks! Remote Support will now close ")
sleep(2)
quit()
sleep(2)
thread.start_new_thread(d,())
r.mainloop()
謝謝君士坦丁,我會檢查一下! –
Constantinius感謝您的輸入我在這裏有一個完整的例子:http://pastebin.com/AD0UAuMS如果您將它包含在您的答案中,它將會很棒。 –