创建列表以填充组合框时出错

时间:2012-03-22 19:17:25

标签: python function wxpython return-value

我花了最后一小时试图看看我做错了什么,或者忽略了什么。我正在尝试根据用户选择的文件的文件扩展名填充组合框。以下是我的代码的关键部分。谢谢你的帮助:

...
unit1 = 'myfile.avi'
...
...

if self.format_combo1 != 'Select Media' or self.format_combo1 != '':
        myFormat = self.format_combo1.GetValue

formats2 =['.avi','.mpeg','.mp4','.flv','.mov','.mpeg4','.mpg','.mp3','.ogg','.wav','.wma']
    FormTypes = [self.formatType(myFormat, formats2)]# Function call here
    self.format_combo2=wx.ComboBox(panel, size=(100, -1),value='Select Format', choices=FormTypes, style=wx.CB_DROPDOWN, pos=(300,81))

...
...

def formatType(self, unit1, formats2):
    auDio = ['.wav','.wma','.mp3','.ogg']
    viDeo = ['.avi','.mpeg','.mp4','.flv','.mov','.mpeg4','.mpg']
    bad_format = ['Invalid Format']
    fileExtension = os.path.splitext(unit1)[1]
    if fileExtension in formats2:
        if fileExtension in auDio:
            return auDio
        elif fileExtension in viDeo:
            return viDeo
    else:

        return bad_format

以下是我收到的回溯消息:

  Traceback (most recent call last):
  File "C:\Users\GVRSQA004\Desktop\D_Converter\med_convrt.py", line 499, in <module>
  frame = dConvert()
  File "C:\Users\GVRSQA004\Desktop\D_Converter\med_convrt.py", line 112, in __init__
  self.format_combo2=wx.ComboBox(panel, size=(100, -1),value='Select Format',          choices=FormTypes, style=wx.CB_DROPDOWN, pos=(300,81))
 File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_controls.py", line 590, in   __init__
 _controls_.ComboBox_swiginit(self,_controls_.new_ComboBox(*args, **kwargs))
 TypeError: String or Unicode type required

1 个答案:

答案 0 :(得分:3)

myFormat = self.format_combo1.GetValue

您在此处为myFormat分配了一个功能对象(可能您的意思是GetValue())。然后,您使用formatType作为第一个参数调用myFormat,该参数应该是一个字符串。