python - wxPython中如何使仪表跟随线程中的下载功能?
问题描述
我是 YouTube 下载器,但仪表进度不遵循下载此视频的功能我希望仪表从视频下载开始,当下载完成时仪表完成
import wx
from pytube import YouTube
from time import sleep
from threading import Thread
class Tube(wx.Frame):
def __init__(self, *args, **kwargs):
super(Tube, self, *args, **kwargs).__init__(parent=None,id=wx.ID_ANY, title="New Frame", size=(600, 400))
self.Centre()
self.panel = wx.Panel(self, id=wx.ID_ANY, name="New Panel")
self.textLink = wx.StaticText(parent=self.panel, id=wx.ID_ANY, label="Edit YouTube URL", pos=(100, 50))
self.editLink = wx.TextCtrl(parent=self.panel, id=wx.ID_ANY, size=(200, 25), pos=(250,50))
self.downloadButton = wx.Button(parent=self.panel, id=wx.ID_ANY, label="Download Video", pos=(250, 100))
self.downloadButton.Bind(event=wx.EVT_BUTTON, handler=self.thread, source=self.downloadButton)
self.progress = wx.Gauge(parent=self.panel, id=wx.ID_ANY, range=100,size=(200,25), pos=(200, 200))
self.Show()
def progressBar(self, *args, **kwargs):
for value in range(101):
wx.CallAfter(self.progress.SetValue, value)
sleep(0.2)
def Download(self, *args, **kwargs):
self.video = YouTube(self.editLink.GetValue())
self.stream = self.video.streams.get_lowest_resolution()
self.stream.download()
def thread(self, *args, **kwargs):
self.threads = []
self.thread1 = Thread(target=self.Download)
self.thread2 = Thread(target=self.progressBar)
self.threads.append(self.thread1)
self.threads.append(self.thread2)
for thread in self.threads:
thread.setDaemon(True)
thread.start()
if __name__ == '__main__':
app = wx.App()
screen = Tube()
app.MainLoop()
解决方案
为什么不使用 wxProgressDialog?
检查对话框示例以获取详细信息...
谢谢你。
推荐阅读
- reactjs - 在 RxJS 主题的上下文中,next('r') 的目的是什么
- javascript - 如何检查数据库是否已更新
- python - 为什么从汤对象中提取文本时 HTML 源代码会发生变化?
- python - TypeError:重复的基类对象
- javascript - 如何使用 AlaSQL 查询嵌套的 json
- python - PyCharm 中的 WSL Conda 环境
- json - 如何在 jsonPath 中测试 JSON 数组
- php - 当用户关闭支付网关中的浏览器选项卡时,如何在其表中添加减少数量的项目
- c# - 使用 Excel 启动 HTML 文件
- python - 修改请求后从另一个视图调用视图(Rest-Framework)