我想在运行时更改wxPython DirPickerCtrl的值。在下面的示例中,我尝试使用SetPath()(代码中的第二行)更改值,但值不会在显示中更改。
有什么想法吗?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import wx
import wx.xrc
class MyFrame2 ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
bSizer6 = wx.BoxSizer( wx.VERTICAL )
self.m_dirPicker3 = wx.DirPickerCtrl( self, wx.ID_ANY, wx.EmptyString, u"Select a folder", wx.DefaultPosition, wx.DefaultSize, wx.DIRP_DEFAULT_STYLE )
bSizer6.Add( self.m_dirPicker3, 0, wx.ALL, 5 )
self.SetSizer( bSizer6 )
self.Layout()
self.Centre( wx.BOTH )
def __del__( self ):
pass
class App(wx.App):
def OnInit(self):
self.frame = MyFrame2(parent=None)
self.frame.Show()
self.SetTopWindow(self.frame)
return True
if __name__ == '__main__':
app = App()
# Trying to change path here
app.frame.m_dirPicker3.SetPath('/')
app.MainLoop()