我正在尝试为youtube dl 制作一个GUI
我使用wxFormBuilder来制作GUI布局,然后通过导入wxFormBuilder生成的代码,在另一个脚本中进行代码编写。GUI工作正常,但我无法获得从下拉菜单中选择的值的索引。
这是定义组合框属性的代码部分
quality_selection_drop_downChoices = [ u"720p", u"Best Quality Available", u"Audio (mp3)", u"Non Youtube" ]
self.quality_selection_drop_down = wx.ComboBox( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size( -1,-1 ), quality_selection_drop_downChoices, 0 )
self.quality_selection_drop_down.SetSelection( 4 )
gbSizer1.Add( self.quality_selection_drop_down, wx.GBPosition( 2, 1 ), wx.GBSpan( 1, 3 ), wx.ALL|wx.EXPAND, 5 )
这是我写的代码,用于检查组合框值是否正确返回
def video_dl(self, event):
print(self.quality_selection_drop_down.GetSelection)
video_dl命令被设置为GUI中某个按钮的事件。它返回
<built-in method GetSelection of ComboBox object at 0x0000017820621670>
我没有给出所选内容的索引。我用GetSelection、GetCurrentSelection、GetValue、GetString、GetStringSelection进行了尝试。所有这些都以与上面提到的相同的方式返回输出。整个代码都在github上,所以你可以看看整个代码:github-reo-
非常感谢您的帮助!!非常感谢。
错误在于,当您获得选择时,您会执行以下操作:
self.quality_selection_drop_down.GetSelection
而不是这个:
self.quality_selection_drop_down.GetSelection() #returns the index of the combobox
self.quality_selection_drop_down.GetStringSelection() #returns the string associated to the combobox
请记住,当您调用一个方法或函数时,必须使用像foo()
这样的左括号和右括号来调用它。在不带括号的情况下调用它,您可以调用它的__repr__()
方法,它会为您提供有关该方法或它所属对象的一般信息