使FileChooserDialog允许用户选择文件夹/目录

时间:2012-06-03 05:41:08

标签: python gtk

是否可以将gtk.FileChooserDialog / gtk.FileChooserButton设置为仅允许用户选择文件夹/目录?

也许我添加了一个目录过滤器来实现这一目标?如何制作以便用户只能选择文件夹?

email_dialog    = gtk.FileChooserDialog(title="Select folder",
                                        buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
email_filter = gtk.FileFilter()
email_filter.set_name("Folder")
email_filter.add_pattern("*")  # whats the pattern for a folder
email_dialog.add_filter(email_filter)

1 个答案:

答案 0 :(得分:8)

email_dialog.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)

文档here