在 AppJar 中选择文件时限制文件类型



我正在创建一个数据导入模块,我需要限制用户仅上传 Excel 工作簿。我正在使用 AppJar 作为 GUI

app = gui('File Selection', '600x600')
app.addImage("Company", "appJar/company.gif")
app.zoomImage("Company", -10)
app.addLabel('title', 'PowerPoint Data Import')
app.setFont(18)
app.addFileEntry('Data File')
def press(button):
if button == "Cancel":
app.stop
else:
entry = app.getEntry('Data File')
print 'Data File:', entry
wb = load_workbook(filename = entry, data_only = True)    
DataImport(wb)
pptxname = entry[:-5] + '.pptx'
prs.save(pptxname)
print "Import Complete"
app.addButtons(['Import', 'Cancel'], press)
app.go()

没有错误消息,但系统将允许选择任何文件类型,并且我无法找到限制它的方法。

为了完成这项工作,我必须创建一个单独的按钮来设置值,而不是使用添加多个按钮的功能。恐怕有点迂回。

def xlsxselect():
xslxfile = app.openBox(title="Choose Import Data", dirName=None, fileTypes=[('excel worksheets', '*.xlsx')],
parent=None, multiple=False, mode='r')
app.setEntry('xlsxfile', xslxfile, callFunction=False)

最新更新