当前位置:网站首页>Pyqt5 rapid development and practice 3.5 menu bar and toolbar
Pyqt5 rapid development and practice 3.5 menu bar and toolbar
2022-07-26 18:29:00 【Ding Jiaxiong】
PyQt5 Rapid development and actual combat
List of articles
3. The first 3 Chapter Qt Designer Use
3.5 Menu bar and toolbar
3.5.1 Interface design

Add Tool Bar


Drag in
ui Convert to py

3.5.2 Effect test
import sys
from PyQt5.QtWidgets import QApplication,QMainWindow,QWidget,QFileDialog
from MainForm import Ui_MainWindow
class MainForm(QMainWindow , Ui_MainWindow):
def __init__(self):
super(MainForm,self).__init__()
self.setupUi(self)
# Menu click events , When you click the close menu, connect the slot function close
self.fileCloseAction.triggered.connect(self.close)
# Menu click events , When you click to open the menu , Connection slot function openMsg()
self.fileOpenAction.triggered.connect(self.openMsg)
def openMsg(self):
file , ok = QFileDialog.getOpenFileName(self," open ","C:/","All Files (*) ;; Text Files (*.txt)")
# Displays the file address in the status bar
self.statusbar.showMessage(file)
if __name__ == '__main__':
from pyqt5_plugins.examples.exampleqmlitem import QtCore
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
app = QApplication(sys.argv)
win = MainForm()
win.show()
sys.exit(app.exec_())

Click on “ open ”

3.5.3 application : Load other windows
A method of embedding another window in the current window .
Create a new normal window

Copy a MainForm

Add a fence layout

ui turn py

Call the main window class CallMainWin02.py
# -*- coding: utf-8 -*-
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QFileDialog
from MainForm2 import Ui_MainWindow
from ChildrenForm2 import Ui_ChildrenForm
class MainForm(QMainWindow, Ui_MainWindow):
def __init__(self):
super(MainForm, self).__init__()
self.setupUi(self)
# self.child = children() Generate child window instances self.child
self.child = ChildrenForm()
# Menu click events , When you click the close menu, connect the slot function close()
self.fileCloseAction.triggered.connect(self.close)
# Menu click events , When you click to open the menu, connect the slot function openMsg()
self.fileOpenAction.triggered.connect(self.openMsg)
# Click on actionTst, The sub window will be displayed in the... Of the main window MaingridLayout in
self.addWinAction.triggered.connect(self.childShow)
def childShow(self):
# Add child window
self.MaingridLayout.addWidget(self.child)
self.child.show()
def openMsg(self):
file, ok = QFileDialog.getOpenFileName(self, " open ", "C:/", "All Files (*);;Text Files (*.txt)")
# Displays the file address in the status bar
self.statusbar.showMessage(file)
class ChildrenForm(QWidget, Ui_ChildrenForm):
def __init__(self):
super(ChildrenForm, self).__init__()
self.setupUi(self)
if __name__ == "__main__":
from pyqt5_plugins.examples.exampleqmlitem import QtCore
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
app = QApplication(sys.argv)
win = MainForm()
win.show()
sys.exit(app.exec_())

边栏推荐
- 14.梯度检测、随机初始化、神经网络总结
- 自动化测试工具-Playwright(快速上手)
- Point cloud target detection Kitti dataset bin file visualization, one-stop solution
- 开发winform中遇到的一些问题汇总(持续跟新)
- 立即报名 | 云原生技术交流 Meetup 广州站已开启,8 月 6 号与你相遇!
- Leetcode 50 day question brushing plan (day 1 - add two numbers 11.00-12.30)
- 8.2 some algebraic knowledge (groups, cyclic groups and subgroups)
- 菜鸟 CPaaS 平台微服务治理实践
- 突发!Arm停止与华为合作!对华为影响究竟有多大?
- 你适合做自动化 测试吗?
猜你喜欢

MPLS实验

链表-反转链表

Oracle第二天(视图、索引、plsql、游标、存储过程和存储函数、触发器、jdbc访问存储过程和存储函数)

剑指offer 正则表达式匹配

How about the employment prospects of Russian translation? How to do a good job of Russian translation

Distributed link tracking Jaeger's use in golang

成为测试/开发程序员,小张:现实就来了个下马威......

How to assemble a registry

Leetcode 50 day question brushing plan (day 5 - longest palindrome substring 10.50-13:00)

Privacy computing basic component series - confusion circuit
随机推荐
[brother hero July training] day 25: tree array
Leetcode 50 day question brushing plan (day 1 - add two numbers 11.00-12.30)
Meta Cambria手柄曝光,主动追踪+多触觉回馈方案
8.2 一些代数知识(群、循环群和子群)
常用功能的测试用例
网易游戏研发工程师实习生(客户端方向)一面
开发winform中遇到的一些问题汇总(持续跟新)
链表-合并两个排序的列表
Distributed link tracking Jaeger's use in golang
DTS is equipped with a new self-developed kernel, which breaks through the key technology of the three center architecture of the two places Tencent cloud database
俄语翻译的就业前景怎样 如何做好俄语翻译工作
Ten year structure five year life-06 impulse to leave
LeetCode50天刷题计划(Day 4—— 最长回文子串 14.00-16:20)
J9 number theory: how to avoid the trap of stepping on thunder?
云服务器mySQL提示报错
【翻译】为什么你需要一个API网关来管理对你的API的访问?
百度飞桨EasyDL X 韦士肯:看轴承质检如何装上“AI之眼”
mpc5744p烧录到98%无法继续下载程序
Linked list - the penultimate K nodes
网上炒股,选择在哪里开户比较安全呢?