就是在我的程序里,要出现tkinter和播放音频,但在运行时,只有关了tkinter才会播放音频,我该怎样才能让他们同时进行
#coding=utf-8
import threading
from time import ctime,sleep
def music(func):
for i in range(2):
print "I was listening to %s. %s" %(func,ctime())
sleep(1)
def move(func):
for i in range(2):
print "I was at the %s! %s" %(func,ctime())
sleep(5)
threads = []
t1 = threading.Thread(target=music,args=(u'1',))
threads.append(t1)
t2 = threading.Thread(target=move,args=(u'2',))
threads.append(t2)
if __name__ == '__main__':
for t in threads:
t.setDaemon(True)
t.start()
print "all over %s" %ctime()
定义两个方法一个操作tkinter,一个播放音频,使用多线程来同时执行。
多线程