简体   繁体   English

PyQt5 ComboBox无法弄清楚

[英]PyQt5 ComboBox can't figure out

Good day! 美好的一天!

I have started to learn Python last week, I am surprised how easy and understandable it is compared to other languages, but I can't figure out one thing. 我上周开始学习Python,与其他语言相比,它是如此简单易懂,我感到很惊讶,但是我一无所知。

I have scraped a table (NBA Team stats from last 5 games) from a website, it updates every day. 我从网站上抓了一张桌子(最近5场比赛的NBA球队统计数据),并且每天更新。 There are 30 rows in that table (30 NBA Teams) and 19 Columns (Stats like Points, Rebounds, Blocks, etc). 该表中有30行(30个NBA球队)和19列(统计数据,如得分,篮板,盖帽等)。

I want to put 30 Team Names in ComboBox Widget and when A Team is chosen, I want it to show data of that specific team (These 19 columns). 我想在ComboBox窗口小部件中放置30个团队名称,选择一个团队时,我希望它显示该特定团队的数据(这19列)。 The Data shown would be in QTableWidget. 显示的数据将在QTableWidget中。

class Window(QWidget):
def __init__(self):
    super().__init__()
    self.initUI()

def initUI(self):

    comboStatsText = QLabel('Home Team', self)
    comboStatsText.move(15, 10)
    comboStatsBox = QComboBox(self)
    comboStatsBox.move(15, 30)


    #Combo Box Data
    comboStatsBox.addItem(name)
    comboStatsBox.addItem(name1)

I have successfully went to stage where I choose A team and a tablewidget pops and shows data, but If I choose another team again, it doesn't change. 我已经成功进入阶段,选择A团队,一个tablewidget弹出并显示数据,但是如果我再次选择另一个团队,它不会改变。 I have looked up how to change it when activated, but I could not do it. 我已经查看了激活后如何更改它,但是我做不到。

I have looked up something with indexes of combobox, could not understand how to implement it. 我已经用combobox的索引查找了某些内容,无法理解如何实现它。 Would it be like this? 会是这样吗?

if index(of combobox) = 1(corresponding team) then show data of that team? 如果索引(组合框)= 1(对应团队),则显示该团队的数据?

I hope you get the idea :/ I am really bad at explaining things and English is not my native language. 希望您能理解:/我真的很难解释事情,英语不是我的母语。 Any help or suggestions would be much appreciated, THANKS!! 任何帮助或建议,将不胜感激,谢谢!

You need to write a function that receives a signal from the combobox for your selection event. 您需要编写一个函数,该函数从组合框接收选择事件的信号。 Perhaps the activated signal. 也许是activated信号。 Then you need to clear the existing tablewidget and write in your new data. 然后,您需要清除现有的tablewidget并写入新数据。

Something like this: 像这样:

combostatsbox.activated.connect(self.load_team)

def load_team():
    self.team_table_widget.clear()
    # Set your values now

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM