我的Python程序有点问题。基本上,它是一个非常简单的文件管理器。在
我一直试图让它在文件夹之间移动(用户单击一个文件夹,程序刷新显示并显示文件夹的内容)。在
我遇到的问题是,我似乎不能让按钮刷新显示,然后填充新的文件夹和文件时,点击。在
这是我正在使用的代码,它在Linux上。在import wx
import fileBrowser
class interface(wx.Frame):
def __init__(self, parent, id):
'''(object, int) --> None
Set up wx python in a frame and displays it and contents defined in this function on the screen.'''
wx.Frame.__init__(self, parent, id, "Bronto", size = (800, 600))
panel = wx.Panel(self)
self.createPanels()
contents = fileBrowser.print_items("/")
wx.StaticText(panel, -1, "/", (50, 10))
col = 50
row = 50
for items in contents:
name = items
col, row = self.makeIcons(panel, (800, 600), name, col, row)
def makeIcons(self, panel, param, name, col, row):
'''(object, object) --> None
Place a button on the window that uses an image as its icon.'''
pic = wx.Image("folder.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
self.button = wx.BitmapButton(panel, -1, pic, pos = (col, row))
wx.StaticText(panel, -1, name, (col + 10, row + 40))
self.Bind(wx.EVT_BUTTON, self.displayContents, self.button)
self.button.SetDefault()
if(col < 600):
return col + 90, row
else:
col = 50
return col, row + 80
def createPanels(self):
'''(object) --> None
Create and place both menu and status bars on the window.'''
status = self.CreateStatusBar()
menubar = wx.MenuBar()
File = wx.Menu()
Edit = wx.Menu()
menubar.append(File,"File")
menubar.Append(Edit, "Edit")
new = wx.MenuItem(File, 101, '&New\tCtrl+N', 'Creates a new document')
File.AppendItem(new)
self.Bind(wx.EVT_MENU, self.NewApplication, id=101)
self.SetMenuBar(menubar)
def NewApplication(self, event):
app = wx.PySimpleApp()
frame = interface(parent = None, id =1)
frame.Show()
app.MainLoop()
def displayContents(self, event):
'''(event) --> None
Display the contents of the folder clicked on'''
#self.panel.Destroy();
#self.panel = wx.Panel(self)
self.Refresh(True)
contents = fileBrowser.print_items("/home")
col = 50
row = 50
for items in contents:
name = items
wx.Yield()
col, row = self.makeIcons(panel, (800, 600), name, col, row)
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = interface(parent = None, id =1)
frame.Show()
app.MainLoop()
这是fileBrower程序(目前我只查看文件夹,但稍后会更改)
^{pr2}$
@pthonm:我添加了你建议的代码,但它似乎没有用新的东西更新它(虽然它确实清除了窗口)
编辑:好吧,我差不多可以用了。我可以使用自我更新(对)但只有当我不使用self.panel.销毁()方法。那么,有没有关于如何删除按钮和文本的建议(请参阅displayContents方法了解我添加的内容)?在
编辑2:我让它发挥作用了。我做的是,我把这个添加到我的displayContents方法中。不过,这可能不是最好的办法。在def displayContents(self, event):
'''(event) --> None
Display the contents of the folder clicked on'''
self.panel.Destroy();
self.panel = wx.Panel(self)
self.createPanels()
self.Update()
wx.StaticText(self.panel, -1, location, (50, 10))
contents = fileBrowser.print_items("/home/gum/Documents")
col = 50
row = 50
for directory,name in contents.iteritems():
col, row = self.makeIcons(self.panel, (800, 600), name, col, row)