Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

update label text in for loop

I’m working on a shopping cart GUI. I have a list called my_order, which stores the information I get from the user. I want to update label text in a for loop so I can print all the elements of my_order list. Here’s my code:

class PaymentScreen(QMainWindow):
    def __init__(self):
        super(PaymentScreen, self).__init__()
        loadUi("paymentscreen.ui",self)
        self.gobackbutton.clicked.connect(self.goback)
        self.basket.setText("{}".format(my_order)) #the output looks like ["burger","fries"] and I dont want that
        

I’m trying to print all the elements one under the another instead of that list view. I looked for the similar cases but couldn’t find the solution.

I want the output to look like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

burger
fries

How can I do that?

I want to update label text

>Solution :

I am no expert in Python GUI but i am good in python programming and I assume you want the string inside setText to be a multiline string. I could help with that.

You can use something line this:

self.basket.setText("\n".join(my_order))

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading