Python easygui无法选择文件 [英] Python easygui can't select file

查看:440
本文介绍了Python easygui无法选择文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

import easygui
f = easygui.fileopenbox()
print f

似乎很简单,但是当我运行它时,我无法选择任何文件,请参见链接中的图.抱歉,这很愚蠢,但我快要死了!

Seems simple, but when I run it, I can't select any of the files, see figure in link. Sorry if this is dumb, but I am at my wit's end!

http://imgur.com/c20TvQ5

推荐答案

EasyGui不再受支持.在OS X上,fileopenbox并没有此问题(实际上看起来像diropenbox会发生什么.)我建议您尝试使用类似wxPython的方法.这是在其中获取文件打开框的方法(来自 https://stackoverflow.com/a/9319832/866271 )

EasyGui isn't supported anymore. On OS X I don't have this problem with fileopenbox (it looks like what happens with diropenbox actually.) I'd recommend you try something like wxPython. Here's how to get a file open box in that (from https://stackoverflow.com/a/9319832/866271)

import wx

def get_path(wildcard):
    app = wx.App(None)
    style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST
    dialog = wx.FileDialog(None, 'Open', wildcard=wildcard, style=style)
    if dialog.ShowModal() == wx.ID_OK:
        path = dialog.GetPath()
    else:
        path = None
    dialog.Destroy()
    return path

print get_path('*.txt')

在OS X上进行了测试,没有问题.它也是跨平台的.如果要进行GUI开发,则有很多选项可供选择,但是wxPython是一个不错的选择,因为它使用了您正在运行的任何操作系统的本机窗口小部件.所以一切看起来都很漂亮:)

Tested on OS X with no problem. It's also cross-platform. If you're going to be doing GUI development, there's a lot of options to look at but wxPython is a good one because it uses the native widgets of whatever OS you're running. So everything looks pretty :)

对于您的情况,如果这是您要打开的文件类型,则可以调用get_path('*.csv').或者只是调用get_path('*')来获取所有这些信息.

For your case, you could instead call get_path('*.csv') if that's the type of file you're opening. Or just call get_path('*') to get all of them.

这篇关于Python easygui无法选择文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆