我遇到了一个问题,让我的列表控制框将参数从一个类传递到另一个类。我使用wxpython创建一个gui,允许用户只从一个目录中选择文件,然后在文本编辑器中打开它。我遇到的问题是,虽然它会打开文件,但不会更新选择。它使其与原始默认选择保持相同。如果能帮上我的忙,我将不胜感激。在
正如你所看到的,如果我在我的机器上使用文本编辑器运行这个程序,它就会知道选择并正确工作。在
import wx
import os
import webbrowser
class list(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'List Directory', size=(600,400))
panel=wx.Panel(self)
kk=os.listdir("/Python/Tutorials/Script")
self.yard=wx.ListBox(panel, -1, (100,50), (400,120), kk, wx.LB_SINGLE)
self.PcuRestart=wx.Button(panel, 1, 'Restart', pos=(0, 30), size=(60, -1))
wx.EVT_BUTTON(panel, self.PcuRestart.GetId(), self.pcurestart)
self.yard.SetSelection(7)
def pcurestart(self, event):
MainWindow().Show()
# self.sel = self.yard.GetSelection()
# self.k = self.yard.GetString(self.sel)
# os.environ['probe1'] = self.k
# print self.k
# os.system("open /Python/Tutorials/Script/$probe1")
class MainWindow(wx.Frame):
def __init__(self, filename='boo.txt'):
super(MainWindow, self).__init__(None, size=(400,200))
self.q = list(parent=None,id=-1)
self.q.yard.Refresh()
self.sel = self.q.yard.GetStringSelection()
self.q.yard.Refresh()
self.filename = 'MainProgram'
w = str(self.sel)
print w
self.dirname = '/Python/Tutorials/Script/'
self.CreateInteriorWindowComponents()
textfile = open(os.path.join("/Python/Tutorials/Script", w ), 'r')
self.control.SetValue(textfile.read())
textfile.close()
def CreateInteriorWindowComponents(self):
self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
if __name__=='__main__':
app=wx.PySimpleApp()
frame=list(parent=None,id=-1)
frame.Show()
app.MainLoop()
非常感谢!在
下面是一些清理后的代码,展示了一种使其显示多个文本文件的方法:
相关问题 更多 >
编程相关推荐