pyqt5 实现工具栏文字图片同时显示

yipeiwu_com6年前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_())

以上这篇pyqt5 实现工具栏文字图片同时显示就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python通用函数实现数组计算的方法

一.数组的运算 数组的运算可以进行加减乘除,同时也可以将这些算数运算符进行任意的组合已达到效果。 >>> x=np.arange(5) >>> x...

ansible作为python模块库使用的方法实例

前言 ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量...

Python多继承以及MRO顺序的使用

多继承以及MRO顺序 1. 单独调用父类的方法 # coding=utf-8 print("******多继承使用类名.__init__ 发生的状态******") class...

Django压缩静态文件的实现方法详析

django静态文件配置原理 静态文件配置就是为了让用户请求时django服务器能找到静态文件返回。 首先要理解几个概念: 媒体文件:用户上传的文件 静态文件:css,js,...

Python实现字符串中某个字母的替代功能

今晚想实现这样一个功能:将输入字符串中的字母 “i” 变成字母 “p”。当时想的很简单,直接用for循环遍历,然后替代,出问题的代码如下: name = input('随便输入一堆字...