如何从wxFilePickerCtrl按钮获取文件路径字符串

How to obtain filepath string from wxFilePickerCtrl button

This is how the output of my GUI looks if I run the program right now 我使用 xrc 为我的程序制作了一个 gui,但我不知道文件路径字符串存储在 wxFilePickerCtrl class 按钮

上的什么位置

在线示例和教程显示命令,例如使用 GetPath() 当然可以更改适合的变量,但在框架中的 filepicker1 中似乎没有该属性,我可以使用按钮选择文件好吧,执行的普通按钮也可以使用,已使用简单的打印命令对其进行了测试。感谢您的帮助

!/usr/bin/python

第一行是这样 运行 而不使用 python 命令

默认导入

import os
import sys

wxdiag 和 src 需要此导入行

import wx
from wx import xrc 

此应用程序用于加载 xrc 文件

class MyApp(wx.App): def init_frame(self): self.res = xrc.XmlResource("test.xrc") self.frame = self.res.LoadFrame(None, "framemain") self.panel = xrc.XRCCTRL(self.frame, "panel1") self.text1 = xrc.XRCCTRL(self.panel, "text1") self.filepicker1 = xrc.XRCCTRL(self.panel, "filepicker1") self.button1= xrc.XRCCTRL(self.panel, "button1")

def OnInit(self):
    self.init_frame()
    self.Bind(wx.EVT_BUTTON, self.OnButton_gobutton, id=xrc.XRCID('button1'))
#--------ListCtrl colums 

#--------call populate functions

#--------this gets the main frame to show
    self.frame.Show()
    return True 

def OnButton_gobutton(self, evt):
    print "hello"

这会加载主框架和每个后续元素,第一行的 none 是因为第一个框架有父框架

if __name__=="__main__":
   app= MyApp(False)
   app.MainLoop()

现在在这条线上

defOnButton_gobutton(self,evt):  

行我设置了一个打印命令来确认按钮正在工作,但是在这个动作中我想从我在 xrc 上设置的 wxFilePickerCtrl class 按钮获取文件路径字符串。目标是选择一个文件,当我单击 GUI 按钮时,我应该对所选文件执行其他操作,但我找不到存储所选文件的#the 字符串的位置。

wxFilePickerCtrlclass(不是按钮)有一个方法GetPath(),returns一个字符串。我可能会遗漏一些东西,但我认为这就是你要找的东西。调用 self.filepicker1.GetPath().