【添加菜单栏-状态栏--20240822】

# case9  添加菜单栏
import sys
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()
    def initUI(self):
        self.resize(800, 600)
        self.center()
        self.setWindowTitle('My_QT_Test')
        self.setWindowIcon(QIcon \
                               ('./Lena.jpg'))
        # 菜单栏
        # 对话框类型
        # QMessageBox.about():关于对话框对象
        # QMessageBox.information():消息对话框对象
        # QMessageBox.warning():警告对话框对象
        # QMessageBox.critical():错误对话框对象
        # QMessageBox.question():提问对话框对象

        # Contorl菜单栏
        menu_control = self.menuBar().addMenu('Contorl')
        # 添加Contorl下的下拉子菜单
        act_quit = menu_control.addAction('quit')
        act_quit.triggered.connect(self.close)
        act_information = menu_control.addAction('information')
        act_information.triggered.connect(self.information)

        # Help菜单栏
        menu_help = self.menuBar().addMenu('Help')
        # 添加Help下的下拉子菜单
        act_about = menu_help.addAction('about...')
        act_about.triggered.connect(self.about)
        act_aboutqt = menu_help.addAction('aboutqt')
        act_aboutqt.triggered.connect(self.aboutqt)

        # 状态栏
        self.statusBar().showMessage('PYQT 程序已就绪,请稍候 @CopyRight 2024 ......')
        self.show()

    def about(self):
        QMessageBox.about(self,'about this software','wise system')

    def aboutqt(self):
        QMessageBox.aboutQt(self)

    # add show function
    def information(self):
        QMessageBox.information(self,'Pyqt','Hello QT')


    def closeEvent(self,event):
        reply = QMessageBox.question(self,'提示','确定退出吗?',QMessageBox.Yes,QMessageBox.No)
        if reply == QMessageBox.Yes:
            event.accept()
        else:
            event.ignore()

    # center method(居中设置)
    def center(self):
        screen = QDesktopWidget().screenGeometry()
        size = self.geometry()
        self.move((screen.width()-size.width())/2,(screen.height()-size.height())/2)


QT_Test = QApplication(sys.argv)
mainwindow = MainWindow()
sys.exit(QT_Test.exec_())
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_44119674

觉得有帮助,鼓励下吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值