当前位置:网站首页>Interface switching based on pyqt5 toolbar button -2
Interface switching based on pyqt5 toolbar button -2
2022-07-02 23:24:00 【Crazy Bean Bun】
Pyqt5 yes Python A visual super easy-to-use library , Next, let's take a look at how to realize the toolbar button switching interface . This chapter mainly introduces how to implement the code , Don't talk much , Begin to introduce .
1. Use pyUIC Tools will mainwindow.ui Convert to “.py” file , The code is as follows :
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'mainwindow.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.widget = QtWidgets.QWidget(self.centralwidget)
self.widget.setGeometry(QtCore.QRect(10, 10, 781, 501))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 127))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 127))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 127))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 127))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
self.widget.setPalette(palette)
self.widget.setAutoFillBackground(True)
self.widget.setObjectName("widget")
self.widget_2 = QtWidgets.QWidget(self.widget)
self.widget_2.setGeometry(QtCore.QRect(160, 110, 451, 231))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
self.widget_2.setPalette(palette)
self.widget_2.setAutoFillBackground(True)
self.widget_2.setObjectName("widget_2")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.toolBar = QtWidgets.QToolBar(MainWindow)
self.toolBar.setObjectName("toolBar")
MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
self.action_1 = QtWidgets.QAction(MainWindow)
self.action_1.setObjectName("action_1")
self.action_2 = QtWidgets.QAction(MainWindow)
self.action_2.setObjectName("action_2")
self.toolBar.addAction(self.action_1)
self.toolBar.addAction(self.action_2)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.toolBar.setWindowTitle(_translate("MainWindow", "toolBar"))
self.action_1.setText(_translate("MainWindow", " Open the interface 1"))
self.action_2.setText(_translate("MainWindow", " Open the interface 2"))
2. stay main.py Enter the following code in :
import sys
from mainwindow import Ui_MainWindow
from PyQt5 import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import QHeaderView, QTableWidgetItem, QHBoxLayout
class MainUI(Ui_MainWindow, QMainWindow):
def __init__(self, parent=None):
super(MainUI, self).__init__(parent)
self.setupUi(self)
def openM(self):
self.widget.show()
self.widget_2.hide()
def openC(self):
self.widget_2.show()
self.widget.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
main = MainUI()
main.show()
main.action_1.triggered.connect(main.openM)
main.action_2.triggered.connect(main.openC)
sys.exit(app.exec_())
3. The interface implemented is as follows , Open the interface 1, Interface 1 appear , Interface 2 hide , Open the interface 2, Interface 1 hide , Interface 2 appear .
summary
After two chapters of detailed introduction , Under the same form , Switching between two interfaces , At the same time, the button is placed in the toolbar , Neat and beautiful .
边栏推荐
- 跨境电商如何通过打好数据底座,实现低成本稳步增长
- SharedPreferences save list < bean > to local and solve com google. gson. internal. Linkedtreemap cannot be cast to exception
- 内网渗透 | 手把手教你如何进行内网渗透
- Quantitative analysis of PSNR, SSIM and RMSE
- [hardware] origin of standard resistance value
- Potplayer set minimized shortcut keys
- vim区间删行注释
- 潘多拉 IOT 开发板学习(HAL 库)—— 实验4 串口通讯实验(学习笔记)
- Win11系统explorer频繁卡死无响应的三种解决方法
- 【STL源码剖析】仿函数(待补充)
猜你喜欢
MySQL queries nearby data And sort by distance
Set right click to select vs code to open the file
基于Pyqt5工具栏按钮可实现界面切换-1
設置單擊右鍵可以選擇用VS Code打開文件
Writing of head and bottom components of non routing components
Win11启用粘滞键关闭不了怎么办?粘滞键取消了但不管用怎么解决
Golang common settings - modify background
海思 VI接入视频流程
Redis expiration policy +conf record
Compose 中的 'ViewPager' 详解 | 开发者说·DTalk
随机推荐
設置單擊右鍵可以選擇用VS Code打開文件
采用VNC Viewer方式遠程連接樹莓派
门牌制作 C语言
BBR 遭遇 CUBIC
Configuration clic droit pour choisir d'ouvrir le fichier avec vs Code
Ping domain name error unknown host, NSLOOKUP / system d-resolve can be resolved normally, how to Ping the public network address?
Print out mode of go
Set right click to select vs code to open the file
【STL源码剖析】仿函数(待补充)
Cryptographic technology -- key and ssl/tls
(毒刺)利用Pystinger Socks4上线不出网主机
CDN acceleration requires the domain name to be filed first
[analysis of STL source code] imitation function (to be supplemented)
[Yangcheng cup 2020] easyphp
Submit code process
4 special cases! Schools in area a adopt the re examination score line in area B!
Doorplate making C language
Strictly abide by the construction period and ensure the quality, this AI data annotation company has done it!
Loss function~
Yolox enhanced feature extraction network panet analysis