现在用wxpython 做联系人应用, 希望实现点击左侧联系人列表刷新右侧联系人信息 现在使用了wx.SplitterWindow, ReplaceWindow(winOld, winNew) 现在点击实现了替换,返回了True 。但是替换后不能在右侧显示。 SplitterWindow 部分代码:
class SplitterContacts(wx.SplitterWindow):
def __init__(self, parent, ID):
wx.SplitterWindow.__init__(self, parent, ID,
style = wx.SP_LIVE_UPDATE)
self.sp = wx.SplitterWindow(self)
self.InitSplitter()
def InitSplitter(self):
self.SetSize((500, 500))
style = wx.BORDER_SUNKEN
with open('contacts.json', 'r') as contacts:
contacts = contacts.read()
contacts = json.loads(contacts)
contact = contacts.values()[0]
left_list = wx.Panel(self, style=style)
left_list = ListContactsPanel(self, style=style, contacts=contacts)
left_list.SetBackgroundColour("sky blue")
right_list = ContactDetail(self, style=style, contact=contact)
right_list.SetBackgroundColour("pink")
self.SetMinimumPaneSize(200)
self.SplitVertically(left_list, right_list, -400)
点击响应事件 处理
def OnColClick(self, evt):
i = evt.GetIndex()
contact = self.contacts.values()[i]
left = self.parent.GetWindow1()
old = self.parent.GetWindow2()
old.SetBackgroundColour("blue")
style = wx.BORDER_SUNKEN
new = ContactDetail(self, style=style, contact=contact)
self.parent.ReplaceWindow(old, new)
old.Destroy()
new.Show(True)
不知道哪里出了错误! 请教一下 谢谢!
终于发现哪里出现了问题
new = ContactDetail(self, style=style, contact=contact)
这一句应该是 new = ContactDetail(self.parent, style=style, contact=contact)
好尴尬