Answer the question
In order to leave comments, you need to log in
PyQt 5: condition with QLabel.setText() does not change value on form, how to fix?
Good afternoon!
There is this code:
def function1(self, args=None):
groupBox = QGroupBox("Титле")
vbox = QVBoxLayout()
vbox.addStretch(1)
groupBox.setLayout(vbox)
integerLabel = QLabel('test')
vbox.addWidget(integerLabel)
print('свойство сейчас:' + integerLabel.text())
if args is not None:
integerLabel.setText('1')
print('Тест попадения функции')
print('Поменялось на:' + args)
print('свойство сейчас 2:' + integerLabel.text())
Answer the question
In order to leave comments, you need to log in
Hello!
And where is the "groupBox" added to the window? I made a simple version with a cool one based on QWidget. Everything is displayed as it should.
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QGroupBox, QVBoxLayout, QLabel, QPushButton
class Example(QWidget):
def __init__(self):
super().__init__()
l = QVBoxLayout()
b = QPushButton('Добавить без параметра!')
b.clicked.connect(lambda: self.function1())
b2 = QPushButton('Добавить с параметром!')
b2.clicked.connect(lambda: self.function1(args='параметр'))
l.addWidget(b)
l.addWidget(b2)
self.setLayout(l)
self.show()
def function1(self, args=None):
groupBox = QGroupBox("Титле")
vbox = QVBoxLayout()
vbox.addStretch(1)
groupBox.setLayout(vbox)
integerLabel = QLabel('test')
vbox.addWidget(integerLabel)
print('свойство сейчас:' + integerLabel.text())
if args is not None:
integerLabel.setText('1')
print('Тест попадения функции')
print('Поменялось на:' + args)
print('свойство сейчас 2:' + integerLabel.text())
self.layout().addWidget(groupBox)
if __name__ == '__main__':
app = QApplication(sys.argv)
w = Example()
w.resize(250, 150)
w.setWindowTitle('Simple')
w.show()
sys.exit(app.exec_())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question