您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關怎么在pyqt5中使用按鈕進行界面跳轉,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
代碼1
import sys from PyQt5.QtWidgets import QMainWindow, QPushButton, QApplication class First(QMainWindow): def __init__(self): super().__init__() self.initUI() def initUI(self): self.btn = QPushButton("Button", self) self.btn.move(30, 50) self.setGeometry(300, 300, 500, 500) self.setWindowTitle('Event sender') self.show() class Second(QMainWindow): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setGeometry(300, 300, 290, 150) self.setWindowTitle('Get sender') if __name__ == '__main__': app = QApplication(sys.argv) a = First() b = Second() a.show() a.btn.clicked.connect(b.show) sys.exit(app.exec_())
代碼2
下面的代碼使用了Qtdesigner的代碼
from PyQt5 import QtCore, QtGui, QtWidgets import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QLabel,\ QPushButton, QLineEdit, QMenuBar, QStatusBar from PyQt5.QtCore import * class FirstWindow(QWidget): def __init__(self, parent=None): # super這個用法是調用父類的構造函數 # parent=None表示默認沒有父Widget,如果指定父親Widget,則調用之 super(FirstWindow, self).__init__(parent) self.setGeometry(500, 500, 500, 500) self.setWindowTitle('顯示') self.btn = QPushButton(self) self.btn.setText('標定') self.btn.move(150, 50) #下面的一部分是Qtdesigner的代碼 class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(624, 479) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.label = QtWidgets.QLabel(self.centralwidget) self.label.setGeometry(QtCore.QRect(190, 130, 51, 31)) self.label.setObjectName("label") self.pushButton = QtWidgets.QPushButton(self.centralwidget) self.pushButton.setGeometry(QtCore.QRect(330, 260, 75, 23)) self.pushButton.setObjectName("pushButton") self.lineEdit = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit.setGeometry(QtCore.QRect(280, 130, 151, 21)) self.lineEdit.setObjectName("lineEdit") self.label_2 = QtWidgets.QLabel(self.centralwidget) self.label_2.setGeometry(QtCore.QRect(190, 180, 51, 31)) self.label_2.setObjectName("label_2") self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit_2.setGeometry(QtCore.QRect(280, 190, 151, 21)) self.lineEdit_2.setObjectName("lineEdit_2") self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget) self.pushButton_2.setGeometry(QtCore.QRect(200, 260, 75, 23)) self.pushButton_2.setObjectName("pushButton_2") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 624, 23)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.label.setText(_translate("MainWindow", " 長")) self.pushButton.setText(_translate("MainWindow", "確定")) self.label_2.setText(_translate("MainWindow", " 寬")) self.pushButton_2.setText(_translate("MainWindow", "取消")) if __name__ == "__main__": app = QApplication(sys.argv) MainWindow = QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) ex = FirstWindow() ex.btn.clicked.connect(MainWindow.show) ex.show() sys.exit(app.exec_())
以上就是怎么在pyqt5中使用按鈕進行界面跳轉,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。