0
就PyQT的使用經驗而言,我遵循示例代碼HERE來做到這一點,但我對如何將啓動下載部分與啓動GUI部件,以便我可以在按下OK(startBtn)按鈕時啓動該部件。另外,知道我所做的命令不會做任何事情,但給你一個錯誤,但我知道這是有效的。
任何幫助表示讚賞!PyQt5:想通過點擊按鈕啓動一個特定的子進程
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QAction, qApp, QDesktopWidget, QPushButton, QHBoxLayout, QVBoxLayout, QTextEdit
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import QThread, QProcess
import sys
class GUI(QProcess):
def __init__(self):
super().__init__()
# Create an instance variable here (of type QTextEdit)
startBtn = QPushButton('OK')
stopBtn = QPushButton('Cancel')
#startBtn.clicked.connect()
stopBtn.clicked.connect(qApp.exit)
self.hbox = QHBoxLayout()
self.hbox.addStretch(1)
self.hbox.addWidget(startBtn)
self.hbox.addWidget(stopBtn)
self.edit = QTextEdit()
self.edit.setWindowTitle("QTextEdit Standard Output Redirection")
self.vbox = QVBoxLayout()
self.vbox.addStretch(1)
self.vbox.addWidget(self.edit)
self.vbox.addLayout(self.hbox)
#setLayout(self.vbox)
self.central=QWidget()
#self.vbox.addWidget(self.edit)
self.central.setLayout(self.vbox)
self.central.show()
def readStdOutput(self):
self.edit.append(str(self.readAllStandardOutput()))
def main():
app = QApplication(sys.argv)
qProcess = GUI()
qProcess.setProcessChannelMode(QProcess.MergedChannels);
qProcess.start("youtube-dl")
qProcess.readyReadStandardOutput.connect(qProcess.readStdOutput);
return app.exec_()
if __name__ == '__main__':
main()
2注:
如果您還知道如何當你按下它,直到處理完畢,那麼我很想知道禁用OK按鈕。
並非所有的進口都被使用,但我可以在以後清理。 PyCharm顯示哪個被使用而不是。清理是爲了以後。
臨屋恩,這會幫助你一噸!這對我來說很難。我使用Youtube-dl和手動更新的.txt文件,以及其他一些參數,但我沒有提供。現在我將學習如何使用GUI更改/添加參數。 – Thomasedv
如果我的答案可以幫助您將其標記爲正確。 – eyllanesc
當然可以。剛剛谷歌如何做到這一點... - .-我是新來的網站...這是如此明顯... – Thomasedv