Windows 7 如何在Python中同时运行两个不同的进程

Windows 7 如何在Python中同时运行两个不同的进程,windows-7,python-3.x,Windows 7,Python 3.x,我正在尝试用运行Windows7的Python3编写一个程序。我希望该程序能够在窗口中显示文本,同时播放音频文件。我可以在不同的时间成功完成这两个过程。如何同时完成这些过程?以下是从程序中提取的代码块: import lipgui, winsound, threading menu = lipgui.enterbox("Enter a string:") if menu == "what's up, lip?": t1 = threading.Th

我正在尝试用运行Windows7的Python3编写一个程序。我希望该程序能够在窗口中显示文本,同时播放音频文件。我可以在不同的时间成功完成这两个过程。如何同时完成这些过程?以下是从程序中提取的代码块:

     import lipgui, winsound, threading
     menu = lipgui.enterbox("Enter a string:") 
     if menu == "what's up, lip?":
        t1 = threading.Thread(target=winsound.PlaySound("C:/Interactive Program/LIP Source Files/skyisup.wav", 2), args=(None))
        t2 = threading.Thread(target=lipgui.msgbox("The sky is up"), args = (None))

Thread
target
参数必须指向要执行的函数。代码在将函数传递给
目标之前对其进行求值

t1 = threading.Thread(target=winsound.PlaySound("C:/Interactive Program/LIP Source Files/skyisup.wav", 2), args=(None))
t2 = threading.Thread(target=lipgui.msgbox("The sky is up."), args = (None))
在功能上与:

val1 = winsound.PlaySound("C:/Interactive Program/LIP Source Files/skyisup.wav", 2)
t1 = threading.Thread(target=val1, args=(None))
val2 = lipgui.msgbox("The sky is up.")
t2 = threading.Thread(target=val2, args=(None))
实际上,您要做的是在计算函数之前只将函数传递给
目标
,并在实例化
线程
时,在
args
参数中传递要传递给所需函数的参数

t1 = threading.Thread(target=winsound.PlaySound, args=("C:/Interactive Program/LIP Source Files/skyisup.wav", 2))
t2 = threading.Thread(target=lipgui.msgbox, args=("The sky is up.",))
现在t1和t2包含线程实例,其中引用了要与参数并行运行的函数。他们还没有运行代码。为此,您需要运行:

t1.start()
t2.start()
确保不要调用
t1.run()
t2.run()
run()
是一种线程方法,它通常在新线程中运行

最终代码应为:

import lipgui
import winsound 
import threading

menu = lipgui.enterbox("Enter a string:") 
if menu == "what's up, lip?":
    t1 = threading.Thread(target=winsound.PlaySound, args=("C:/Interactive Program/LIP Source Files/skyisup.wav", 2))
    t2 = threading.Thread(target=lipgui.msgbox, args=("The sky is up",))

    t1.start()
    t2.start()

你能在前面给出更多的代码吗。当前代码中发生了什么?它应该可以工作,并使两者同时运行。编辑它。这是完整的脚本。它仍然会在不同的时间执行这些操作!很抱歉迟了回复!现在当我运行这个程序时,它会播放音频,程序会继续运行,但不会显示GUI!你好我还是搞不懂!编辑了我原来的帖子。我想问题是我们在单独的行上做t1.start和t2.start。我真的需要帮助!