#!/usr/bin/python # -*- coding: utf-8 -*- import sys from PyQt4 import QtGui, QtCore class Example(QtGui.QWidget): def __init__(self): super(Example, self).__init__() self.initUI() def initUI(self): lbl2 = QtGui.QLabel('Π’Π²Π΅Π΄ΠΈΡ‚Π΅ количСство ΠΊΠ»Π΅Ρ‚ΠΎΠΊ Π² ΠΊΠ²Π°Π΄Ρ€Π°Ρ‚Π΅ ', self) # это Π²ΠΈΠ΄ΠΆΠ΅Ρ‚ ΠΏΡ€ΠΎΠΏΠΈΡΡ‹Π²Π°ΡŽΡ‰ΠΈΠΉ строчку lbl2.move(15, 10) qbtn = QtGui.QPushButton('Π’Π²ΠΎΠ΄', self) # это ΠΊΠ½ΠΎΠΏΠΊΠ° ΠΎΡ‚Π²Π΅Ρ‡Π°ΡŽΡ‰Π°Ρ Π·Π° Π²Ρ‹ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ qbtn.move(90, 130) self.connect (qbtn, QtCore.SIGNAL("clicked()") ,self.on_clicked) self.lbl = QtGui.QLabel(self) # эта надпись привязана ΠΊ строчкС qle self.lbl.move(60, 90) qle = QtGui.QLineEdit(self) # строчка ΠΎΡ‚Π²Π΅Ρ‡Π°ΡŽΡ‰Π°Ρ Π·Π° ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠΈ Π½Π° надписи lbl qle.move(60, 40) qle.textChanged[str].connect(self.onChanged) # ΠΌΠ΅Ρ…Π°Π½ΠΈΠΊΠ° связки qle self.qle = qle #textCopyButton = QtGui.QPushButton("&Copy Text", self) #self.connect(textCopyButton, QtCore.SIGNAL("clicked()"), self.copyText) #selfconnect(self.button, QtCore.SIGNAL("clicked()"),self.on_clicked) self.setGeometry(300, 300, 280, 170) self.setWindowTitle('Π—ΠΌΠ΅ΠΉΠΊΠ°') self.show() #def copyText(self): #clipboard = QApplication.clipboard() #clipboard.setText("I've been clipped!") def onChanged(self, text): # ΠΌΠ΅Ρ…Π°Π½ΠΈΠΊΠ° связки qle self.lbl.setText(text) self.lbl.adjustSize() def on_clicked(self): #self.lbl.setText("HoΠ²aя надпись" ) self.input_value = self.qle.text() print (self.input_value) if not self.input_value.isdigit(): print ('Π²Ρ‹ Π²Π²Π΅Π»ΠΈ Π½Π΅ число ' * 3 ) **self.lbl.setText("Π²Ρ‹ Π²Π²Π΅Π»ΠΈ Π½Π΅ число !" ) # сСт тСкст Π½Π΅ ΠΎΡ‚ΠΎΠ±Ρ€Π°ΠΆΠ°Π΅Ρ‚ ΠΏΠΎΠ»Π½ΠΎΡΡ‚ΡŒΡŽ надпись** else: num = int(self.input_value) if num < 40: print ('слишком ΠΌΠ°Π»Π΅Π½ΠΊΠΎΠ΅ количСство ΠΊΠ»Π΅Ρ‚ΠΎΠΊ ΠΈΠ³Ρ€Π°Ρ‚ΡŒ Π±ΡƒΠ΄Π΅Ρ‚ Π½Π΅ интСрСсно ') **self.lbl.setText('слишком ΠΌΠ°Π»Π΅Π½ΠΊΠΎΠ΅ количСство ΠΊΠ»Π΅Ρ‚ΠΎΠΊ ΠΈΠ³Ρ€Π°Ρ‚ΡŒ Π±ΡƒΠ΄Π΅Ρ‚ Π½Π΅ интСрСсно ')** else: summaMassiv1 = int(num) * int(num) print ( summaMassiv1 ) #self.qbtn.setDisabled(True) def main(): app = QtGui.QApplication(sys.argv) ex = Example() sys.exit(app.exec_()) if __name__ == '__main__': main() 

In general, self.lbl.setText("Π²Ρ‹ Π²Π²Π΅Π»ΠΈ Π½Π΅ число !" ) does not display the inscription self.lbl.setText("Π²Ρ‹ Π²Π²Π΅Π»ΠΈ Π½Π΅ число !" ) but rather displays it only if I entered letters in an amount equal to the size of this phrase

    1 answer 1

    I tried on Windows. I had to replace:

     self.input_value.isdigit() 

    on:

     str(self.input_value).isdigit() 

    ... otherwise, an exception was thrown: AttributeError: 'QString' object has no attribute 'isdigit'

    You obviously have a problem with the layout of the form. The default QLabel object seems to move the text field automatically when it reaches some kind of content limit, which you experienced and found.