pyqt5 realize drop-down menu + open file sample code
As shown below:
# -*- coding: utf-8 -*- import sys import os from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets from import QRect, QSize, QMetaObject, QCoreApplication,\ QPropertyAnimation from import QFont from import QFileDialog from import QWidget, QHBoxLayout, QGridLayout, QPushButton,\ QApplication, QMainWindow class Ui_MainWindow(object): def setupUi(self, MainWindow): ("MainWindow") (800, 681) ((0, 651)) ("background-image: url(:/new prefix (linguistics)/);") = (MainWindow) ("centralwidget") = () ((0, -580, 195, 631)) ("widget") = () ((0, 0, 195, 581)) (True) ("scrollArea") = () ((0, 0, 178, 681)) ((177, 681)) ("scrollAreaWidgetContents") = () ((0, -10, 181, 691)) ("verticalLayoutWidget") = () (0, 0, 0, 0) (20) ("verticalLayout") self.pushButton_2 = () self.pushButton_2.setObjectName("pushButton_2") (self.pushButton_2) self.label_2 = () self.label_2.setObjectName("label_2") (self.label_2) self.pushButton_4 = () self.pushButton_4.setObjectName("pushButton_4") (self.pushButton_4) self.label_3 = () self.label_3.setObjectName("label_3") (self.label_3) self.pushButton_7 = () self.pushButton_7.setObjectName("pushButton_7") (self.pushButton_7) self.label_4 = () self.label_4.setObjectName("label_4") (self.label_4) self.pushButton_6 = () self.pushButton_6.setObjectName("pushButton_6") (self.pushButton_6) self.label_5 = () self.label_5.setObjectName("label_5") (self.label_5) self.pushButton_5 = () self.pushButton_5.setObjectName("pushButton_5") (self.pushButton_5) self.label_6 = () self.label_6.setObjectName("label_6") (self.label_6) = () ("pushButton") () self.label_7 = () self.label_7.setObjectName("label_7") (self.label_7) () = () ((50, 580, 61, 32)) ("border-image: url(:/new prefix (linguistics)/);") ("") ("closeButton") = () ((50, 0, 61, 32)) ("border-image: url(:/new prefix (linguistics)/);") ("") ("openButton") = () ((0, 0, 801, 641)) ("graphicsView") .raise_() .raise_() .raise_() () = (MainWindow) ((0, 0, 800, 22)) ("menubar") = () ("menu") () = (MainWindow) ("statusbar") () = (MainWindow) ("action") self.action_2 = (MainWindow) self.action_2.setObjectName("action_2") self.action_3 = (MainWindow) self.action_3.setObjectName("action_3") () (self.action_2) (self.action_3) (()) (MainWindow) (MainWindow) def retranslateUi(self, MainWindow): _translate = (_translate("MainWindow", "MainWindow")) self.pushButton_2.setText(_translate("MainWindow", "PushButton")) self.label_2.setText(_translate("MainWindow", "TextLabel")) self.pushButton_4.setText(_translate("MainWindow", "PushButton")) self.label_3.setText(_translate("MainWindow", "TextLabel")) self.pushButton_7.setText(_translate("MainWindow", "PushButton")) self.label_4.setText(_translate("MainWindow", "TextLabel")) self.pushButton_6.setText(_translate("MainWindow", "PushButton")) self.label_5.setText(_translate("MainWindow", "TextLabel")) self.pushButton_5.setText(_translate("MainWindow", "PushButton")) self.label_6.setText(_translate("MainWindow", "TextLabel")) (_translate("MainWindow", "PushButton")) self.label_7.setText(_translate("MainWindow", "TextLabel")) (_translate("MainWindow", "Human Brain Architecture Analysis")) (_translate("MainWindow", "Import Matrix")) self.action_2.setText(_translate("MainWindow", "Exit the system.")) self.action_3.setText(_translate("MainWindow", "Developer Information")) class Window(QMainWindow, Ui_MainWindow): def __init__(self, *args, **kwargs): super(Window, self).__init__(*args, **kwargs) (self) = QPropertyAnimation(, b"geometry") # Hidden controls behind (1000) # 1s (QRect(0, 30, 178, 681)) # It's just the x-coordinate that changes # Move in animation = QPropertyAnimation(, b"geometry") # Hidden controls behind (1000) # 1s (QRect(0, -580, 178, 681)) () # Bind open close events () () # Open the file () ('Import Matrix') ('Ctrl+Q') # Exit the system self.action_2.() self.action_2.setStatusTip('Exit the system') self.action_2.setShortcut('Ctrl+E') #Developer Information self.action_3.setStatusTip('Tang Weize Xie Jiake 2016.12.3') def onOpen(self): # Set button invisible (False) (True) # Behind the controls to be pulled out are visible ((195, 1, 611, 641)) () # Turn on animation effects def onClose(self): () # Stop if it moves halfway () # Back it up def onFinish(self): # Close the end of the animation (False) (True) ((0, 0, 801, 641)) def openFile(self): fileName1, filetype = (self,"Selected documents","/Users/Kelisiya/Desktop","All Files (*);;Text Files (*.txt)") print(fileName1, filetype) if __name__ == "__main__": import sys app = QApplication() w = Window() () (app.exec_())
Above this pyqt5 implementation of the drop-down menu + open the file sample code is all that I have shared with you, I hope to give you a reference, and I hope you support me more.
Related articles
python automated email delivery
This article is mainly for you to introduce in detail the python to realize the automatic sending of mail, with certain reference value, interested partners can refer to it2019-08-08Python basic tutorials of Pandas data analysis library details
Pandas is a very powerful open source data processing library based on NumPy, which provides efficient, flexible and rich data structure and data analysis tools, in this article, we will learn how to use Pandas to process and analyze data, interested partners follow the editor to take a look at it!2023-07-07Using OpenCV to implement affine transformation-rotation function
This article introduces the implementation of OpenCV in the affine transformation - rotation function, this article through the example code to give you a very detailed, with certain reference value, you can refer to the next!2019-08-08Implementing ipaddress network address handling in Python
The ipaddress library provides classes to handle IPv4 and IPv6 network addresses. These classes support authentication, finding addresses and hosts on a network, and other common operations. This article describes the use of these methods for those interested in learning more about them.2021-06-06python based ini configuration file manipulation utility class
This article is mainly for you to introduce ini configuration file based on python operation tools, with certain reference value, interested partners can refer to it!2019-04-04Django URL parameters Template reverse parsing
This article introduces the Django URL parameters Template reverse analysis, the text of the sample code through the introduction of the very detailed, for everyone's learning or work has a certain reference learning value, need friends can refer to the following2020-11-11Python JWT Introduction and Usage Details
This article introduces the Python JWT introduction and use of the details, the text through the sample code is very detailed, for everyone's learning or work has a certain reference learning value, the need for friends below with the editorial to learn together!2021-05-05python openpyxl implementation of copying tables with formatting
This article introduces the python openpyxl with formatting to copy the form of the realization of the operation, with a good reference value, I hope to help you. Together follow the editor over to see it2021-03-03Initial use of Tensorboard, Tensorflow's visualization tool, in detail
This article introduces the Tensorflow visualization tool Tensorboard initial use of detailed, I think it is quite good, now share it with you, but also to give you a reference. Follow the editor over to see it together2018-02-02python optical simulation PyQt5 basic framework tutorial
This article introduces the python optical simulation of PyQt5 basic framework tutorial, the text contains a detailed implementation of the sample analysis, the need for friends can learn from the reference, I hope to be able to help!2021-10-10