嘿,我在使用进度栏以及同时运行的流程时遇到问题

问题描述

您可以阅读下面的代码获取详细信息。主要问题是,按下转换键时,它确实将视频转换为音频,但是进度条不起作用,“ pB.join()”之后的语句也没有执行,并且我的程序停止响应。我也尝试使用标志全局变量来杀死函数中的线程,但它也无法正常工作。在tkinter的情况下,线程使用可能受到限制。期待答案。

'''

    import moviepy.editor as mp
    from tkinter import *
    from tkinter.ttk import Progressbar,Style
    import tkinter.font as font
    import time
    import threading

    #Conversion Function
    def convertToAudio():
        finished = False
        result.configure(text=" ")
        window.update()
        time.sleep(1)
        pB = threading.Thread(target=progressBar,args=(lambda : finished,))
        pB.start()          #I do not think the thread starts as the function is not executed
        try:
            f1 = Video.get()
            f2 = Audio.get()
            clip = mp.VideoFileClip(f1)    
            clip.audio.write_audiofile(f2)
            finished = True
            pB.join()
            result.configure(text="DONE")   #This statement does not get executed
        except:
            finished = True
            pB.join()
            result.configure(text="Failed") #This statement does not get executed

    #Progress Bar   
    def progressBar(finished):
        i=1
        while(True):
            progress['value'] = (20*i)%120
            window.update()
            time.sleep(0.4)
            i+=1
            if(finished()):
                break


    #Main Window
    #Basic
    window = Tk()
    window.geometry("500x200")
    window.title("MP3 CONVERTER")
    window.configure(bg = "grey")
    Myfont = font.Font(family="Calibri",size=16)

    #Variables
    Video = StringVar()
    Audio = StringVar()

    #Video
    L1 = Label(window,font =Myfont,text="VIDEO FILE :",background="grey")
    L1.place(x=100,y=40)
    E1 = Entry(window,textvariable = Video)
    E1.place(x=215,y=45,width=200)

    #Audio
    L2 = Label(window,font=Myfont,text="AUdio FILE :",background="grey")
    L2.place(x=98,y=70)
    E2 = Entry(window,textvariable = Audio)
    E2.place(x=215,y=75,width=200)

    #Main Button
    convert = Button(window,text="Convert",command=convertToAudio)
    convert.place(x=334,y=105,height=25)

    #Result Label
    result = Label(window,background="grey")
    result.place(x=230,y=160)

    #Loading
    progress = Progressbar(window,orient=HORIZONTAL,length=100,mode='indeterminate')
    progress.place(x=210,y=130)

    window.mainloop()

'''

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)