繁体   English   中英

PyQT5 label 未显示

[英]PyQT5 label is not showing

我想显示“正在转换...”,但未显示。
但是,显示“已转换”。
我试图更改“正在转换...”等的位置,但它不起作用..
我找不到解决此问题的参考。 TT
我的代码如下。 谢谢!
你好。 我想显示“正在转换...”,但未显示。
但是,显示“已转换”。
我试图更改“正在转换...”等的位置,但它不起作用..
我找不到解决此问题的参考。 TT
我的代码如下。 谢谢!



import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QIcon
from moviepy.editor import *
import argparse


class MyApp(QWidget):

    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):

        self.setWindowTitle('Video2GIF')
        # self.setWindowIcon(QIcon('./assets/logo.png'))
        self.setGeometry(300, 300, 300, 200)

        self.pushButton = QPushButton('Open File')
        self.pushButton.clicked.connect(self.pushButtonClicked)

        self.label = QLabel()

        layout = QVBoxLayout()
        layout.addWidget(self.pushButton)
        layout.addWidget(self.label)

        self.setLayout(layout)

    def pushButtonClicked(self):

        self.fileName = QFileDialog.getOpenFileName(
            self, "open file", "./", "mp4 file(*.mp4) ;; avi file(*.avi)")

        if self.fileName[0]:
            self.label.setText("Converting...")

            inputName = self.fileName[0]
            outputName = inputName[:-4] + '.gif'
            print(inputName)
            print(outputName)
            videoClip = VideoFileClip(inputName)
            videoClip.write_gif(outputName)
            # self.label.setText(" ")
            self.label.setText("Converted!")

        else:
            self.label.setText("No file selected")

    # def convert(self):
    #     inputName = self.fileName[0]
    #     outputName = inputName[:-4] + '.gif'
    #     print(inputName)
    #     print(outputName)
    #     videoClip = VideoFileClip(inputName)
    #     videoClip.write_gif(outputName)
    #     self.label.setText(" ")
    #     self.convertedLabel.setText("Converted!")


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = MyApp()
    # print(str(ex.label.isVisible()))
    ex.show()
    sys.exit(app.exec_())

导入这个小部件

from PyQt5.QtWidgets import  QApplication

然后像这样修改你的 function :

def pushButtonClicked(self):

    self.fileName = QFileDialog.getOpenFileName(
        self, "open file", "./", "mp4 file(*.mp4) ;; avi file(*.avi)")

    if self.fileName[0]:
        self.label.setText("Converting...")
        QApplication.processEvents()
        QApplication.processEvents()
        inputName = self.fileName[0]
        outputName = inputName[:-4] + '.gif'
        print(inputName)
        print(outputName)
        videoClip = VideoFileClip(inputName)
        videoClip.write_gif(outputName)
        # self.label.setText(" ")
        self.label.setText("Converted!")

    else:
        self.label.setText("No file selected")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM