【问题标题】:Restrict File Types when selecting files in AppJar在 AppJar 中选择文件时限制文件类型
【发布时间】:2019-09-06 23:44:51
【问题描述】:

我正在创建一个数据导入模块,我需要限制用户只上传 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()

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

【问题讨论】:

    标签: python appjar


    【解决方案1】:

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

    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)
    

    【讨论】:

      猜你喜欢
      • 2019-12-08
      • 2011-11-26
      • 1970-01-01
      • 2012-08-23
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 2014-11-26
      相关资源
      最近更新 更多