创建一个包括菜单栏,工具栏,状态栏,文本编辑部件的经典GUI应用程序的骨架...

效果如下:

 

代码如下:

 1 #!/usr/bin/python3
 2 # -*- coding: utf-8 -*-
 3 
 4 """
 5 This program creates a skeleton of
 6 a classic GUI application with a menubar,
 7 toolbar, statusbar, and a central widget.
 8 
 9 """
10 
11 import sys
12 from PyQt5.QtWidgets import QMainWindow, QTextEdit, QAction, QApplication
13 from PyQt5.QtGui import QIcon
14 
15 
16 class Example(QMainWindow):
17 
18     def __init__(self):
19         super().__init__()
20 
21         self.initUI()
22 
23     def initUI(self):
24 
25         textEdit = QTextEdit()
26         self.setCentralWidget(textEdit)
27 
28         exitAct = QAction(QIcon('pictures\exit24.png'), 'Exit', self)
29         exitAct.setShortcut('Ctrl+Q')
30         exitAct.setStatusTip('Exit application')
31         exitAct.triggered.connect(self.close)
32 
33         self.statusBar()
34 
35         menubar = self.menuBar()
36         fileMenu = menubar.addMenu('&File')
37         fileMenu.addAction(exitAct)
38 
39         toolbar = self.addToolBar('Exit')
40         toolbar.addAction(exitAct)
41 
42         self.setGeometry(300, 300, 350, 250)
43         self.setWindowTitle('Main window')
44         self.show()
45 
46 
47 if __name__ == '__main__':
48 
49     app = QApplication(sys.argv)
50     ex = Example()
51     sys.exit(app.exec_())

 

转载于:https://www.cnblogs.com/fuqia/p/8711151.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值