英文:
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))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论