的文件該主窗口,顯示這裏有一個可運行的例子,你想要做什麼。
import wx
class ListTest(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, size=(380, 230))
panel = wx.Panel(self, -1)
#Create a list
self.list = wx.ListCtrl(panel, -1, style=wx.LC_REPORT)
self.list.InsertColumn(0, 'File-path', width=140)
#Do the layout
hbox = wx.BoxSizer(wx.HORIZONTAL)
hbox.Add(self.list, 1, wx.EXPAND)
panel.SetSizer(hbox)
self.Centre()
self.Show(True)
#Create Menu
menubar = wx.MenuBar()
file = wx.Menu()
self.loadFile = wx.MenuItem(file, -1, '&Open\tCtrl+L', 'Open a file')
file.AppendItem(self.loadFile)
menubar.Append(file, '&File')
self.SetMenuBar(menubar)
self.Bind(wx.EVT_MENU, self.on_openFile)
def on_openFile(self, evt):
loadFileDlg = wx.FileDialog(
self, message="Open File",
defaultDir="",
defaultFile="",
style=wx.OPEN | wx.CHANGE_DIR
)
#If the user clicked the open file button
if loadFileDlg.ShowModal() == wx.ID_OK:
#Get the file path
path = loadFileDlg.GetPath()
loadFileDlg.Destroy()
#Call your file analysis method or whatever here
#Create a message dialog
fileAnalysedDlg = wx.MessageDialog(self, "File Has Been Analysed", "File Has Been Analysed", wx.OK)
fileAnalysedDlg.ShowModal()
fileAnalysedDlg.Destroy()
#Add filepath to list
self.list.InsertStringItem(0, path)
app = wx.App()
ListTest(None, 'list test')
app.MainLoop()
AFAIK沒有。你想達到什麼目的?也許有另一種方式... – volting 2010-08-26 22:43:42
@volting:謝謝你!我試過你的代碼,它的工作!我發現了我的錯誤。主要區別在於listctrl是一個實例,它有一個self.Bind(wx.EVT_CHAR_HOOK,...),所以當按下按鍵時,它會響應並做一些更改。我試圖做的是將文件的名稱顯示到listctrl中,當我點擊彈出對話框 – serina 2010-08-26 22:48:45
上的「ok」按鈕時,我實現了一個框架,好吧,它是與原始圖片不同的實例一個,即:第一個是處的代理,第二個是>處的
serina
2010-08-26 22:51:22