Domanda

Here is part of my code that is in my function which is called when a user presses a button on the GUI.

self.titlelbl.clear()  #clear labels
self.genrelbl.clear()
self.ratinglbl.clear()
#........ Other code ....

self.titlelbl = QLabel(self.movie['title'])  #Labels, defined earlier 
self.genrelbl = QLabel(self.movie['genre'])
self.ratinglbl = QLabel(self.movie['rating'])

self.titlelbl.show()     #Show labels
self.genrelbl.show()
self.ratinglbl.show()

The issue I'm having is that when the new labels show up again the information on the labels is correct but the GUI opens up a new window for each label instead of just displaying them in the main GUI window, like it displays when you first open the program. What is causing this?

Thank you.

È stato utile?

Soluzione

You need to specify parent for each label.

...
self.titleLbl = QLabel(self, self.movie['title'])
...

then add the labels to the layout of the mainWindow.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top