当前位置:网站首页>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 .
边栏推荐
- PotPlayer设置最小化的快捷键
- Innovation strength is recognized again! Tencent security MSS was the pioneer of cloud native security guard in 2022
- 万物并作,吾以观复|OceanBase 政企行业实践
- Loss function~
- Catalogue of digital image processing experiments
- The difference between new and make in golang
- [analysis of STL source code] imitation function (to be supplemented)
- Use of recyclerview with viewbinding
- 【Proteus仿真】51单片机+LCD12864推箱子游戏
- Simple square wave generating circuit [51 single chip microcomputer and 8253a]
猜你喜欢
STM32之ADC
密码技术---分组密码的模式
【Redis笔记】压缩列表(ziplist)
Why does RTOS system use MPU?
Detailed explanation and application of merging and sorting
Connexion à distance de la tarte aux framboises en mode visionneur VNC
Where is the win11 microphone test? Win11 method of testing microphone
Win11麦克风测试在哪里?Win11测试麦克风的方法
海思 VI接入视频流程
Catalogue of digital image processing experiments
随机推荐
[analysis of STL source code] imitation function (to be supplemented)
Loss function~
Jinglianwen technology's low price strategy helps AI enterprises reduce model training costs
理想汽车×OceanBase:当造车新势力遇上数据库新势力
Realize the linkage between bottomnavigationview and navigation
What if win11 can't turn off the sticky key? The sticky key is cancelled but it doesn't work. How to solve it
BBR 遭遇 CUBIC
BBR encounters cubic
Use the scroll bar of souI when using the real window in souI
Tiktok actual combat ~ number of likes pop-up box
Innovation strength is recognized again! Tencent security MSS was the pioneer of cloud native security guard in 2022
抖音实战~点赞数量弹框
可知论与熟能生巧
Go basic data type
Sword finger offer II 099 Sum of minimum paths - double hundred code
Eight honors and eight disgraces of the programmer version~
【直播预约】数据库OBCP认证全面升级公开课
用matlab调用vs2015来编译vs工程
Pandora IOT development board learning (HAL Library) - Experiment 3 key input experiment (learning notes)
Application of containerization technology in embedded field