PyQt6实例_批量下载pdf工具_界面开发
目录
前置:
代码:
视频:
前置:
1 本系列将以 “PyQt6实例_批量下载pdf工具”开头,放在 【PyQt6实例】 专栏
2 本系列涉及到的PyQt6知识点:
线程池:QThreadPool,QRunnable;
信号与槽:pyqtSignal,pyqtSlot;
界面:QTextEdit,QLabel,QLineText,QPushButton,QMainWindow,QWidget;
布局:QHBoxLayout,QVBoxLayout;
弹框:QFileDialog,QMessageBox。
3 本系列后续会在B站录制视频,到时会在文末贴出链接。本人还是建议先看博文,不懂的再看视频,这样效率高,节约时间。
代码:
from datetime import datetime
from PyQt6.QtCore import (
QSize,Qt
)
from PyQt6.QtWidgets import(
QApplication,
QMainWindow,
QLabel,
QLineEdit,
QPushButton,
QFileDialog,
QTextEdit,
QHBoxLayout,
QVBoxLayout,
QWidget
)
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle('PDF Downloader')
self.setMinimumSize(QSize(600,400))
label1 = QLabel('存储pdf网址txt文件所在目录:')
self.txtdir_lineedit = QLineEdit()
self.choicedir_btn = QPushButton('打开目录')
self.choicedir_btn.clicked.connect(self.choicedir_btn_clicked)
label2 = QLabel('设置下载后pdf存储目录:')
self.savedir_lineedit = QLineEdit()
self.savedir_btn = QPushButton('设置目录')
self.savedir_btn.clicked.connect(self.savedir_btn_clicked)
self.execute_btn = QPushButton('执行')
self.execute_btn.clicked.connect(self.execute_btn_clicked)
self.stop_btn = QPushButton('停止')
self.stop_btn.clicked.connect(self.stop_btn_clicked)
label3 = QLabel('运行日志:')
label4 = QLabel('其他信息:')
self.excutelog_textedit = QTextEdit()
self.excutelog_textedit.setReadOnly(True)
self.otherlog_textedit = QTextEdit()
self.otherlog_textedit.setReadOnly(True)
layout0 = QHBoxLayout()
layout0.addWidget(label1)
layout0.addWidget(self.txtdir_lineedit)
layout0.addWidget(self.choicedir_btn)
layout1 = QHBoxLayout()
layout1.addWidget(label2)
layout1.addWidget(self.savedir_lineedit)
layout1.addWidget(self.savedir_btn)
layout2 = QHBoxLayout()
layout2.addWidget(self.execute_btn)
layout2.addWidget(self.stop_btn)
layout3 = QVBoxLayout()
layout3.addWidget(label3)
layout3.addWidget(self.excutelog_textedit)
layout4 = QVBoxLayout()
layout4.addWidget(label4)
layout4.addWidget(self.otherlog_textedit)
layout5 = QHBoxLayout()
layout5.addLayout(layout3)
layout5.addLayout(layout4)
layout = QVBoxLayout()
layout.addLayout(layout0)
layout.addLayout(layout1)
layout.addLayout(layout2)
layout.addLayout(layout5)
widget = QWidget()
widget.setLayout(layout)
self.setCentralWidget(widget)
pass
def choicedir_btn_clicked(self):
dir_name = QFileDialog.getExistingDirectory(self,"打开存储pdf网址txt文件所在目录")
if dir_name:
self.txtdir_lineedit.setText(dir_name)
pass
def savedir_btn_clicked(self):
dir_name = QFileDialog.getExistingDirectory(self, "指定下载后pdf存储的目录")
if dir_name:
self.savedir_lineedit.setText(dir_name)
pass
def execute_btn_clicked(self):
pass
def stop_btn_clicked(self):
pass
def insert_executelog(self,msg:str):
pre_str = f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} {msg}"
self.excutelog_textedit.append(pre_str)
pass
def insert_otherlog(self,msg:str):
pre_str = f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} {msg}"
self.otherlog_textedit.append(pre_str)
pass
pass
if __name__ == '__main__':
app = QApplication([])
window = MainWindow()
window.show()
app.exec()
pass
视频:
https://www.bilibili.com/video/BV1V2ZcYCE6N/
https://www.bilibili.com/video/BV1V2ZcYCELF/