wxpython中如何设置目录路径 [英] how to set the directory path in wxpython

查看:117
本文介绍了wxpython中如何设置目录路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置目录的路径,它会搜索该特定路径并列出其中的所有文件.

I would like to set the path of the directory and it searches for that particular path and lists all the files in it.

例如,我需要在代码中设置目录路径 A = C:\Users\Downloads, B = C:\Users\Documents, C = C:\Users\Desktop.And when A is selected it needs to load the above specified directory and list all the files in listbox.

For Examples, I need to set path of the directory A = C:\Users\Downloads, B = C:\Users\Documents, C = C:\Users\Desktop in the code. And when A is selected it needs to load the above specified directory and list all the files in listbox.

  1. 如何为每个元素(A、B、C..)设置目录----> 我尝试使用 wx.DirDialog 但它总是加载最后选择的或默认的目录.

  1. How to set the directory for each elements(A,B,C..) ----> I tried using wx.DirDialog but it always loads the last selected or default directory.

选择任何元素时,它应该在代码中加载指定的目录,并列出文件.

When any element is selected it should load the specified directory in the code and lists the files.

推荐答案

这是一个简单的起点.
它使用 wx.FileDialog,因为您希望列出文件而不是目录 (wx.DirDialog).
从激活对话框的 wx.Choice 中选择一个目录,以列出该目录中的文件.
目前该程序仅打印选定文件的列表,我将加载列表框留给您.

Here is a simple starting point.
It uses wx.FileDialog as you wish to list files not directories (wx.DirDialog).
Select a directory from a wx.Choice which activates the dialog, to list the files within that directory.
Currently the program only prints a list of selected files, I leave the loading of a listbox to you.

import wx

class choose(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, -1, "Dialog")
        mychoice = ['Select a directory','/home/rolf', '/home/public','/home/public/Documents']
        panel = wx.Panel(self,-1)
        select_dir = wx.Choice(panel,-1, choices=mychoice, pos=(20,20))
        self.Bind(wx.EVT_CHOICE, self.OnSelect)
        self.dir = mychoice[0]
        select_dir.SetSelection(0)
        self.Show()

    def OnSelect(self, event):
        if event.GetSelection() == 0:
            return
        self.dir = event.GetString()
        dlg = wx.FileDialog(None, message="Choose a file/files", defaultDir = self.dir, style=wx.FD_MULTIPLE)
        if dlg.ShowModal() == wx.ID_OK:
            print('Selected files are: ', dlg.GetPaths())
        dlg.Destroy()


if __name__ == '__main__':
    my_app = wx.App()
    choose(None)
    my_app.MainLoop()

这篇关于wxpython中如何设置目录路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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