M
M
Molchanov Stanislav2020-10-20 16:10:44
Python
Molchanov Stanislav, 2020-10-20 16:10:44

How to use text in label?

I'm currently learning pyqt5 and want to do something like a list. Now I am faced with the problem that I need the program to define the text in the label, and if it is there, then write it in another designated place.
I tried
tte = ui.label.setText()
But didn't help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
doktorfish0078, 2020-10-21
@YaMaShu

Well, look.
To get the text contained in the label, you need to write
self.название_вашего_лейбла_в_форме.text()
Respectively Take it and check for emptiness

if len(self.название_вашего_лейбла_в_форме.text()) != 0: #т.е. если есть хоть один символ в тексте лейбла
            self.название_вашего_лейбла_в_форме.setText("Текст,который вы хотите присвоить в другую метку")

You also wrote tte = ui.label.setText()
It makes no sense to assign this to any variable, this setText method returns nothing
Also, here is a link to options for connecting a UI form to code in python ( How to achieve the visibility of objects created in Qt Designer forms when developing code in PyCharm ? )

A
Andrey Boyko, 2020-10-20
@AndreasFxPro

The text should just change or on clicking on something?
P.S. Try

tte = ui.label.setText("Тут текст")
ui.label.repaint()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question