PyQt5 – 在窗口中设置状态栏信息

PyQt5 – 在窗口中设置状态栏信息

在这篇文章中,我们将看到如何为窗口的状态栏设置信息。

状态栏 是一个图形控制元素,它是一个信息区域,通常在窗口的底部。它可以被分成几个部分来分组信息。它的工作主要是显示有关其窗口的当前状态的信息。

为了达到这个目的,我们将使用showMessage()方法。

语法: self.statusBar().showMessage(message)

参数: 它使用字符串作为参数。

执行的动作: 它将消息设置到状态栏。

代码。

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")
  
        # creating a label widget
        self.label_1 = QLabel("Status Bar", self)
  
        # moving position
        self.label_1.move(100, 100)
  
        # setting up the border
        self.label_1.setStyleSheet("border :5px solid blue;")
  
        # resizing label
        self.label_1.resize(80, 100)
  
        # 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教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程