In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "PyQt5 how to achieve Baidu picture downloader GUI interface", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "PyQt5 how to achieve Baidu picture downloader GUI interface" it!
Through Pyqt5 to achieve an interface downloader, through the network request to achieve the download of various types of pictures. You can enter keywords for different pictures on the interface to download the picture and save the downloaded picture to a custom file path.
Before introducing the contents of the code block, let's take a look at the three-party python libraries that need to be used.
From PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5.QtGui import * import osfrom scripy_images import ScripyImages
Then the remaining two operation libraries, one is the os module, which is mainly used to do the operations related to the system files, and the other is the scripy_images module, which is used to obtain and download pictures through network requests.
Next, we introduce the use of Pyqt5-related page definitions and other functions. Similarly, we first add the required components to the Pyqt5 window, and finally by adding these components to the layout, the approximate implementation process is implemented in this order.
Def init_ui (self): self.setWindowTitle ('Baidu Image extraction App') grid = QGridLayout () self.page_label = QLabel () self.page_label.setText ('set the number of crawled pages:') self.page_line_text = QLineEdit () self.page_line_text.setPlaceholderText ('enter integer') self.page_line_text.setValidator (QIntValidator (1) 99) self.page_line_text.setFocus () self.keyword_label = QLabel () self.keyword_label.setText ('set the key word:') self.keyword_line_text = QLineEdit () self.keyword_line_text.setValidator (QRegExpValidator (QRegExp ('[\ u4E00 -\ u9FA5] +')) self.keyword_line_text.setMaxLength (6) self .keyword _ line_text.setPlaceholderText ('input Chinese characters') self.file_path = QLineEdit () self.file_path.setPlaceholderText ('custom file path') self.file_path.setReadOnly (True) self.file_path_button = QPushButton () self.file_path_button.setText ('custom path') self.file_path_button.clicked.connect (self. File_path_click) self.request_button = QPushButton () self.request_button.setText ('start grabbing pictures quickly') self.request_button.clicked.connect (self.download_image) self.log_text = QTextEdit () self.log_text.setPlaceholderText ('display of crawling progress results') Self.log_text.setReadOnly (True) self.log_text.setMaximumHeight self.version_msg_label = QLabel () self.version_msg_label.setText ('official account: [Python concentration Camp] release') self.version_msg_label.setAlignment (Qt.AlignCenter) grid.addWidget (self.page_label, 0,0,1,1) grid.addWidget (self.page_line_text, 0,1,1) 2) grid.addWidget (self.keyword_label, 1,0,1,1) grid.addWidget (self.keyword_line_text, 1,1,2) grid.addWidget (self.file_path, 2,0,1,2) grid.addWidget (self.file_path_button, 2,2,1,1) grid.addWidget (self.request_button, 3,0,1,3) grid.addWidget (self.log_text, 4) 0,1,3) grid.addWidget (self.version_msg_label, 5,0,1,3) self.setLayout (grid)
The next step is to define the corresponding slot function, in which there are two slot functions that need a slot function to get the file path when using a path that actually defines the storage of the file. Another is to start the process of downloading Baidu pictures, through this slot function to call the execution of the download module.
Def file_path_click (self): self.cwd = os.getcwd () directory = QFileDialog.getExistingDirectory (self, 'Select folder' Self.cwd) print (directory) self.file_path.setText (directory +'/') def download_image (self): check_param = False self.log_text.setText ("") self.log_text.insertPlainText ("- start required parameter check -\ n") if self.page_line_text.text () .strip () ! =''and\ self.keyword_line_text.text (). Strip ()! =' 'and\ self.file_path.text (). Strip ()! =': self.log_text.insertPlainText ("--parameter check succeeded -\ n") check_param = True else: self.log_ Text.insertPlainText ("- Parameter check failed -\ n") self.log_text.insertPlainText ("Please fill in the required entry and continue.\ n") check_param = False self.log_text.insertPlainText ("- end required parameter check -\ n") if check_param is True: self.log_text .insertPlainText ("- start downloading Baidu pictures -\ n") self.log_text.insertPlainText ("--Please be patient -\ n") ScripyImages (page_num=self.page_line_text.text () Current=self.keyword_line_text.text (), file_path=self.file_path.text () self.log_text.insertPlainText ("- end downloading Baidu pictures -\ n")
Then the main function is called to execute the entire logic.
If _ _ name__ = ='_ main__': app = QApplication (sys.argv) baidu = baiduImage () baidu.show () sys.exit (app.exec_ ()) so far, I believe you have a deeper understanding of "how PyQt5 implements Baidu image downloader GUI interface". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 226
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.