PyQt4 learning --- the menu bar (addMenu) of 1, the toolbar (addToolBar), TextEdit tool box

 

If that record --- the menu bar PyQt4 learning (addMenu), toolbar (addToolBar), TextEdit tool box

Tencent classroom learning courses from:

__author__ = "lingjun"
# 公众号:小白CV

# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtCore
from PyQt4 import QtGui

QtCore.QTextCodec.setCodecForTr(QtCore.QTextCodec.codecForName("utf8"))

class MainWindow(QtGui.QMainWindow):
    def __init__(self,parent=None):
        QtGui.QMainWindow.__init__(self)

        self.resize(550,450)
        self.setWindowTitle(u'我的主程序')

        # TextEdit工具框
        textEdit=QtGui.QTextEdit()
        self.setCentralWidget(textEdit)

        # 建立exit的action动作,在菜单栏/工具栏均add
        exit=QtGui.QAction(QtGui.QIcon('exit.png'),u'退出',self)
        exit.setShortcut('Ctrl+Q')  # 提示快捷键,但并不能快捷键控制
        exit.setStatusTip(u'退出程序')  # 提示信息
        exit.connect(exit,QtCore.SIGNAL('triggered()'),QtGui.qApp,QtCore.SLOT('quit()'))
        self.statusBar()    # 提示信息进行显示

        # 建立菜单栏
        menubar=self.menuBar()
        file=menubar.addMenu(u'文件')
        file.addAction(exit)

        # 建立工具栏
        toolbar=self.addToolBar(u'退出')
        toolbar.addAction(exit)

if __name__ == "__main__":
    app=QtGui.QApplication(sys.argv)
    main=MainWindow()
    main.show()
    app.exec_()

exit.png image is an exit icon, Baidu own can download a picture, you can zoom out

White CV: No. designed to focus public CV (computer vision), AI (artificial intelligence) technology-related fields, the main content of the article around the C ++, Python programming techniques, machine learning (ML), the depth of learning (DL), OpenCV image processing, etc. technology, explore the depth of technical points, study and work record common operations, problems do you learn to work assistant. Only concerned with technology, the professional knowledge sharing platform CV field.

 

Published 74 original articles · won praise 64 · views 130 000 +

Guess you like

Origin blog.csdn.net/wsLJQian/article/details/97270659