当前位置:网站首页>菜单栏+状态栏+工具栏==PYQT5
菜单栏+状态栏+工具栏==PYQT5
2022-07-25 10:48:00 【栋哥修炼日记】
工具栏
- 提供了一个快速访问的入口
import sys
from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QApplication
from PyQt5.QtGui import QIcon
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
# 我们创建一个简单的工具栏。工具栏有有一个按钮, 点击关闭窗口。
exitAction = QAction(QIcon('exit.png'), 'Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.triggered.connect(qApp.quit)
self.toolbar = self.addToolBar('Exit')#工具栏添加按钮,按钮的功能在上面的三行已经设置好了
self.toolbar.addAction(exitAction)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('Toolbar')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
菜单栏
- 是常见的窗口应用程序的一部分
import sys
from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QApplication
from PyQt5.QtGui import QIcon
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
exitAction = QAction(QIcon('./exit.png'), '&Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(qApp.quit)
self.statusBar()
# 创建一个菜单栏
menubar = self.menuBar()
# 添加菜单
fileMenu = menubar.addMenu('&File')
# 添加事件
fileMenu.addAction(exitAction)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('Menubar')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
状态栏
- 用于显示状态信息。
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.statusBar().showMessage('Ready')
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Statusbar')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
综合一下
- 将上面三个结合起来
- 我们将创建一个菜单条,工具栏和状态栏的小窗口
import sys
from PyQt5.QtWidgets import QMainWindow, QTextEdit, QAction, QApplication
from PyQt5.QtGui import QIcon
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
textEdit = QTextEdit()
self.setCentralWidget(textEdit)
exitAction = QAction(QIcon('exit.png'), 'Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(self.close)
self.statusBar()
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(exitAction)
toolbar = self.addToolBar('Exit')
toolbar.addAction(exitAction)
self.setGeometry(300, 300, 350, 250)
self.setWindowTitle('Main window')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
边栏推荐
- Summary of combination problems of Li Kou brush questions (backtracking)
- SQL injection less23 (filter comment)
- Information management system for typical works of urban sculpture (picture sharing system SSM)
- LVS load balancing lvs-nat building Web Cluster
- ArcMap cannot start the solution
- Mlx90640 infrared thermal imager temperature measurement module development notes (V)
- Convert string to number
- SQL injection LESS18 (header injection + error injection)
- 为什么重写equals()方法必须要重写hashCode()方法
- Dynamic planning problem 03_ Maximum sub segment sum
猜你喜欢

SQL language (4)

爬虫基础一

Let sports happen naturally, and fire creates a new lifestyle

Learn PHP -- phpstudy tips mysqld Exe: Error While Setting Value ‘NO_ ENGINE_ Solution of substitution error

全网显示 IP 归属地,是怎么实现的?

The B2B2C multi merchant system has rich functions and is very easy to open!!!

活动报名 | 玩转 Kubernetes 容器服务提高班正式开营!

让运动自然发生,FITURE打造全新生活方式

Mlx90640 infrared thermal imager temperature measurement module development notes (V)

Smart cloud IOT platform STM32 esp8266-01s simple wireless light control
随机推荐
leetcode 剑指 Offer 27. 二叉树的镜像
Esp8266 uses drv8833 drive board to drive N20 motor
SQL language (V)
Why should the hashcode () method be rewritten when rewriting the equals () method
SQL injection LESS18 (header injection + error injection)
SQL language (III)
论文解读(MaskGAE)《MaskGAE: Masked Graph Modeling Meets Graph Autoencoders》
Nowcodertop12-16 - continuous updating
推荐系统-协同过滤在Spark中的实现
Database integrity -- six constraints learning
游戏背包系统,“Inventory Pro插件”,研究学习-----妈妈再也不用担心我不会做背包了(Unity3D)
工作面试总遇秒杀?看了京东T8大咖私藏的秒杀系统笔记,已献出膝盖
shell-第五章作业
Shell - Chapter 8 exercise
[recursion] 938. Range and of binary search tree
DICOM medical image viewing and browsing function based on cornerstone.js
NowCoderTOP7-11——持续更新ing
2022 年中回顾|一文看懂预训练模型最新进展
Syncronized lock upgrade process
Hacker introductory tutorial (very detailed) from zero basic introduction to proficiency, it is enough to read this one.