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解析中国天气网的天气数据

使用方法:terminal中输入复制代码 代码如下:python weather.py http://www.weather.com.cn/weather/101010100.shtml...

Python打印输出数组中全部元素

学习Python的人都知道数组是最常用的的数据类型,为了保证程序的正确性,需要调试程序。 因此,需要在程序中控制台中打印数组的全部元素,如果数组的容量较小,例如 只含有10个元素,采用p...

如何通过python画loss曲线的方法

如何通过python画loss曲线的方法

1. 首先导入一些python画图的包,读取txt文件,假设我现在有两个模型训练结果的records.txt文件 import numpy as np import matplotl...

python 内置模块详解

一.random模块  随机       random()    随机小数 ...

关于pycharm中pip版本10.0无法使用的解决办法

关于pycharm中pip版本10.0无法使用的解决办法

一、背景: 近期在利用 pycharm 安装第三方库时会提示 pip 不是最新版本, 因此对 pip 进行更新,但是生成最新版本之后, pip 中由于缺少 main 函...