PyQt5 – 为状态栏添加标签

PyQt5 – 为状态栏添加标签

在这篇文章中,我们将看到如何在状态栏中添加标签。我们可以通过使用showMessage方法来设置状态栏的文本。

Label 和StatusBar ?

标签 是一个图形控制元素,在表单中显示文本。它通常是一个静态控件;没有交互性。标签通常用于识别附近的文本框或其他小部件。 状态栏是一个 水平栏,通常在屏幕或窗口的底部,显示正在编辑的文档或正在运行的程序的信息。

为了 做到这一点,我们将采取以下步骤。

1.创建一个标签

2.为标签添加文本

3.创建状态栏的对象

4.在状态栏上添加标签

代码:

from PyQt5.QtCore import * 
from PyQt5.QtGui import * 
from PyQt5.QtWidgets import * 
import sys
  
  
class Window(QMainWindow):
    def __init__(self):
        super().__init__()
  
        # set the title
        self.setWindowTitle("Python")
  
        # setting  the geometry of window
        self.setGeometry(60, 60, 600, 400)
  
        # setting status bar message
        self.statusBar().showMessage("This is status bar")
  
        # setting  border and padding with different sizes
        self.statusBar().setStyleSheet("border :3px solid black;")
  
        # creating a label widget
        self.label_1 = QLabel("Label 1")
  
  
        # setting up the border
        self.label_1.setStyleSheet("border :2px solid blue;")
  
        # adding label to status bar
        self.statusBar().addPermanentWidget(self.label_1)
        # show all the widgets
        self.show()
  
  
# create pyqt5 app
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
  
  
# start the app
sys.exit(App.exec())

PyQt5 - 为状态栏添加标签

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程