• 菜单栏、工具栏、状态栏


    菜单栏

    '''
    
    创建和使用菜单
    
    '''
    
    import sys,math
    from PyQt5.QtWidgets import *
    from PyQt5.QtGui import *
    from PyQt5.QtCore import *
    
    class Menu(QMainWindow) :
        def __init__(self):
            super(Menu,self).__init__()
            bar = self.menuBar()  # 获取菜单栏
    
            file = bar.addMenu("文件")
            file.addAction("新建")
    
            save = QAction("保存",self)
            save.setShortcut("Ctrl + S")
            file.addAction(save)
    
            save.triggered.connect(self.process)
    
            edit = bar.addMenu("Edit")
            edit.addAction("copy")
            edit.addAction("paste")
            quit = QAction("退出",self)
            file.addAction(quit)
    
        def process(self,a):
            print(self.sender().text())
    
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        main = Menu()
        main.show()
        sys.exit(app.exec_())


    image

    工具栏

    '''
    
    创建和使用工具栏
    
    工具栏默认按钮:只显示图标,将文本作为悬停提示展示
    
    工具栏按钮有3中显示状态
    
    1.  只显示图标
    2.  只显示文本
    3.  同时显示文本和图标
    '''
    
    import sys,math
    from PyQt5.QtWidgets import *
    from PyQt5.QtGui import *
    from PyQt5.QtCore import *
    
    class Toolbar(QMainWindow) :
        def __init__(self):
            super(Toolbar,self).__init__()
            self.initUI()
        def initUI(self):
            self.setWindowTitle("工具栏例子")
            self.resize(300,200)
    
            tb1 = self.addToolBar("File")
    
            new = QAction(QIcon('./images/new.png'),"new",self)
            tb1.addAction(new)
    
            open = QAction(QIcon('./images/open.png'),"open",self)
            tb1.addAction(open)
    
            save = QAction(QIcon('./images/save.png'),"save",self)
            tb1.addAction(save)
    
    
            tb2 = self.addToolBar("File1")
            new1 = QAction(QIcon('./images/new.png'),"新建",self)
            tb2.addAction(new1)
    
            tb2.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
    
            tb1.actionTriggered.connect(self.toolbtnpressed)
    
            tb2.actionTriggered.connect(self.toolbtnpressed)
        def toolbtnpressed(self,a):
            print("按下的工具栏按钮是",a.text())
    
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        main = Toolbar()
        main.show()
        sys.exit(app.exec_())

    image

    状态栏

    '''
    
    创建和使用状态栏
    
    '''
    
    import sys,math
    from PyQt5.QtWidgets import *
    from PyQt5.QtGui import *
    from PyQt5.QtCore import *
    
    class StatusBar(QMainWindow) :
        def __init__(self):
            super(StatusBar,self).__init__()
            self.initUI()
        def initUI(self):
            self.setWindowTitle("状态栏演示")
            self.resize(300,200)
    
            bar = self.menuBar()
            file = bar.addMenu("File")
            file.addAction("show")
            file.triggered.connect(self.processTrigger)
            self.setCentralWidget(QTextEdit())
            self.statusBar = QStatusBar()
            self.setStatusBar(self.statusBar)
    
    
        def processTrigger(self,q):
            if q.text() == "show" :
                self.statusBar.showMessage(q.text() + " 菜单被点击了",5000)
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        main = StatusBar()
        main.show()
        sys.exit(app.exec_())
    image
    天道酬勤 循序渐进 技压群雄
  • 相关阅读:
    [转]敏捷软件开发 需求分析
    Windows服务控制命令SC
    [转]敏捷测试工程师的十条法则
    大道至简:如何准确把握趋势 一
    Sqlserver xml 类型操作
    微软Teched2010大会一日游记
    [转]任务、用例、用户故事和场景
    ASUS TF600T上手体验
    Windows 8的各种小发现——不断更新中
    Surface Pro电磁笔故障
  • 原文地址:https://www.cnblogs.com/wuyuan2011woaini/p/14822754.html
Copyright © 2020-2023  润新知