[PyQt] In QtPy5 QLabel.setText() is not a built-in method?

Florian Bruhin me at the-compiler.org
Tue Apr 26 05:36:33 BST 2016


* James Peabody <james.peabody at me.com> [2016-04-25 17:10:38 -0600]:
> I am attempting to change the text of a QLabel programmatically to become the value contained in a type(str).
> 
> No matter how I try, this causing an abend of pythonw.

I'm guessing you mean abort?

This is likely caused by a python exception - if you start your
application in a terminal with python.exe it should tell you more.

> This appears to be virgin ground after searching google and this
> mail list. Interrogating the objects I am using I can see that the
> instance of my QLabel has a <built-in method text QLabel object…>
> but it does not have a <built-in method setText QLabel object…>.

How are you interrogating it?

> It might be noteworthy that I can use setText() and pass a literal
> and that does work as one might expect.

So it *does* have a setText method then, otherwise that wouldn't work.

> How does one go about altering the text of QLabels with the contents of a string?

This works as you'd expect:

    from PyQt5.QtWidgets import QLabel, QApplication
    app = QApplication([])
    label = QLabel()
    text = "I am a string"
    label.setText(text)
    label.show()
    app.exec_()

My guess would be that the thing you're passing to setText is not
actually a string, but something else.

Florian

-- 
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160426/77332daa/attachment.sig>


More information about the PyQt mailing list