在 for 循环中更新标签文本。

huangapple go评论57阅读模式
英文:

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:

burger
fries

How can I do that?

I want to update label text

英文:

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:

burger
fries

How can I do that?

I want to update label text

答案1

得分: 0

我不是Python GUI方面的专家,但我擅长Python编程,我猜你想要setText内的字符串是多行字符串。我可以帮你解决这个问题。

你可以使用类似这样的代码:

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

英文:

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))

huangapple
  • 本文由 发表于 2023年2月6日 18:04:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75359844.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定