zoukankan      html  css  js  c++  java
  • 创建子菜单

    效果如下:

    代码如下:

     1 """
     2 ZetCode PyQt5 tutorial
     3 This program creates a submenu.
     4 """
     5 
     6 import sys
     7 from PyQt5.QtWidgets import QMainWindow, QAction, QMenu, QApplication
     8 
     9 
    10 class Example(QMainWindow):
    11 
    12     def __init__(self):
    13         super().__init__()
    14 
    15         self.initUI()
    16 
    17     def initUI(self):
    18 
    19         menubar = self.menuBar()
    20         fileMenu = menubar.addMenu('File')
    21 
    22         # New menu is created with QMenu. 
    23         impMenu = QMenu('Import', self)
    24         impAct = QAction('Import mail', self)
    25         # An action is added to the submenu with addAction(). 
    26         impMenu.addAction(impAct)
    27 
    28         newAct = QAction('New', self)
    29 
    30         fileMenu.addAction(newAct)
    31         fileMenu.addMenu(impMenu)
    32 
    33         self.setGeometry(300, 300, 300, 200)
    34         self.setWindowTitle('Submenu')
    35         self.show()
    36 
    37 
    38 if __name__ == '__main__':
    39 
    40     app = QApplication(sys.argv)
    41     ex = Example()
    42     sys.exit(app.exec_())
  • 相关阅读:
    3.15第三周编程总结
    2019.3.9编程总结
    2019.3.3编程总结2
    编程总结1
    编程总结2
    编程总结3
    我的老师
    关于sublime text 3使用记录
    12. 整数转罗马数字
    4. 寻找两个有序数组的中位数
  • 原文地址:https://www.cnblogs.com/fuqia/p/8708760.html
Copyright © 2011-2022 走看看