Basically, I'm making a program that relies on random generation from lists. The first generation works fine but I want it so that when I press the "random" button, the field is automatically updated with another name. I'm new to PyQt (a few days) and Python in general so a little help would be appreciated


Qt Code:
  1. def random_hero(self):
  2. hero_dict = ["Adagio", "Alpha", "Ardan", "Baron", "Blackfeather", "Catherine", "Celeste", "Flicker", \
  3. "Fortress", "Glaive", "Gwen", "Idris", "Joule", "Kestrel", "Koshka", "Krul", "Lance", "Lyra", "Ozo", "Petal", \
  4. "Phinn", "Reim", "Ringo", "Rona", "Samuel", "Saw", "Skaarf", "Skye", "Taka", "Vox"]
  5. num = 1
  6. newRandomHero = random.sample(hero_dict,num)
  7. global randHeroName
  8. randHeroName = newRandomHero[0]
  9. print (randHeroName)
  10. heroName = randHeroName
  11.  
  12. def tab3UI(self):
  13. self.setGeometry(250, 100, 800, 300)
  14. layout = QGridLayout()
  15. hero_dict = ["Adagio", "Alpha", "Ardan", "Baron", "Blackfeather", "Catherine", "Celeste", "Flicker", \
  16. "Fortress", "Glaive", "Gwen", "Idris", "Joule", "Kestrel", "Koshka", "Krul", "Lance", "Lyra", "Ozo", "Petal", \
  17. "Phinn", "Reim", "Ringo", "Rona", "Samuel", "Saw", "Skaarf", "Skye", "Taka", "Vox"]
  18. num = 1
  19. randomHero = random.sample(hero_dict,num)
  20.  
  21. layout.addWidget(QLabel("Hero:"),0,0)
  22. global heroName
  23. heroName = layout.addWidget(QLabel(randHeroName),0,1)
  24.  
  25. self.btnRandomHero = QPushButton("Random")
  26. layout.addWidget(self.btnRandomHero,0,3)
  27. self.btnRandomHero.clicked.connect(self.random_hero)
  28.  
  29. blankSpaceLabel1 = layout.addWidget(QLabel(""),0,4,0,8)
  30. blankSpaceLabel1 = layout.addWidget(QLabel(""),1,0,0,8)
  31.  
  32. self.setTabText(2,"Ultimate Bravery")
  33. self.tab3.setLayout(layout)
To copy to clipboard, switch view to plain text mode