在 PyQt 中,可以使用 QLabelQSpinBox 后添加文字内容。首先,创建一个 QLabel,然后使用 QHBoxLayoutQSpinBoxQLabel 放在一起,最后将这个布局设置给父级窗口或布局。

下面是一个示例代码:

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QSpinBox, QLabel, QHBoxLayout

class MainWindow(QWidget):
    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):
        spinBox = QSpinBox()
        label = QLabel('个')
        
        layout = QHBoxLayout()
        layout.addWidget(spinBox)
        layout.addWidget(label)

        self.setLayout(layout)

        self.setGeometry(300, 300, 250, 150)
        self.setWindowTitle('QSpinBox Example')
        self.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    mainWindow = MainWindow()
    sys.exit(app.exec_())

运行这段代码,将会创建一个带有一个 QSpinBox 和一个带有'个'文字的 QLabel 的窗口。

在 PyQt 中使用 QLabel 在 QSpinBox 后添加文字

原文地址: https://www.cveoy.top/t/topic/qy2A 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录