2
我花了最後一小時試圖查看我做錯了什麼,或者忽略了什麼。我試圖根據用戶選擇的文件的文件擴展名填充組合框。以下是我的代碼的關鍵部分。感謝您的幫助:創建列表以填充組合框時出錯
...
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
下面是我得到的回溯消息:您要指定myFormat
一個函數對象這裏
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
'myFormat'的類型是什麼(檢查'type(myFormat)')?它似乎是一個函數而不是一個字符串。 – 2012-03-22 19:20:29