大数据 爬虫Python AI Sql小猿圈-IT自学人的小圈子

小猿圈是全免费?Python开发之pyqt5实现工具栏文字图片同

2019-06-13  本文已影响0人  f673630174f6

对于学习Python人工智能的朋友来说,很多知识点都没有接触过,需要一点点的去接触,观看视频等等,今天小猿圈Python讲师分享pyqt5实现工具栏文字图片同时显示,希望对你学习Python的你有所帮助。

如下所示:

import sys

from PyQt5.QtWidgets import QMainWindow, QTextEdit, QAction, QApplication

from PyQt5.QtGui import QIcon

from PyQt5.QtCore import Qt

class Example(QMainWindow):

  def __init__(self):

    super().__init__()

    self.initUI()

  def initUI(self):

    textEdit = QTextEdit()

    self.setCentralWidget(textEdit)

    exitAction = QAction(QIcon('images/exit.png'), 'Exit',self)

    exitAction.setShortcut('Ctrl+Q')

    exitAction.setStatusTip('Exit application')

    exitAction.triggered.connect(self.close)

    self.statusBar()

    menubar = self.menuBar()

    fileMenu = menubar.addMenu('&File')

    fileMenu.addAction(exitAction)

    toolbar = self.addToolBar('Exit')

    # toolbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) # 文字图片垂直排列

    toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) # 文字图片水平排列

    toolbar.addAction(exitAction)

    self.setGeometry(300, 300, 350, 250)

    self.setWindowTitle('Main window')

    self.show()

if __name__ == '__main__':

  app = QApplication(sys.argv)

  ex = Example()

  sys.exit(app.exec_())

Python是一个可以持续发展的技术,无论是什么方向都可以有自己的一番作为,你有想过学习Python交流群:242719133,想学习Python可以到小猿圈去直接观看,小猿圈是全免费?恭喜你答对了,全部免费这里面从基础到实战的所有学习资料,可以满足你提升自己,为你实现编程梦想的起点。

上一篇下一篇

猜你喜欢

热点阅读