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

Restrict File Types when selecting files in AppJar

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

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)