我正在编写一个与 Skype 集成的聊天程序。我已经完成了大部分的跑腿工作,但是我在 wxPython 中的 Notebook 控件上遇到了问题。当用户发送消息时,我想在笔记本上创建一个新选项卡,我正在工作,但我遇到的问题是如何在选项卡上的面板上引用 TextCtrl?以下是我从网上提取的另一个项目的代码:
import wx
class Page(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
t = wx.StaticText(self, -1, "THIS IS A PAGE OBJECT", (20,20))
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Notebook Remove Pages Example")
pannel = wx.Panel(self)
vbox = wx.BoxSizer(wx.VERTICAL)
hbox = wx.BoxSizer(wx.HORIZONTAL)
self.buttonRemove = wx.Button(pannel, id=wx.ID_ANY, label="DELETE", size=(80, 25))
self.buttonRemove.Bind(wx.EVT_BUTTON, self.onButtonRemove)
hbox.Add(self.buttonRemove)
self.buttonInsert = wx.Button(pannel, id=wx.ID_ANY, label="CREATE", size=(80, 25))
self.buttonInsert.Bind(wx.EVT_BUTTON, self.onButtonInsert)
hbox.Add(self.buttonInsert)
self.buttonMessage = wx.Button(pannel, id=wx.ID_ANY, label="Message", size=(80, 25))
self.buttonMessage.Bind(wx.EVT_BUTTON, self.onButtonMessage)
hbox.Add(self.buttonList)
vbox.Add(hbox)
self.Notebook3 = wx.Notebook(pannel)
vbox.Add(self.Notebook3, 2, flag=wx.EXPAND)
pannel.SetSizer(vbox)
self.pageCounter = 0
self.addPage()
def addPage(self):
self.pageCounter += 1
page = Page(self.Notebook3)
pageTitle = "Page: {0}".format(str(self.pageCounter))
self.Notebook3.AddPage(page, pageTitle)
def onButtonRemove(self, event):
page_to_delete = self.Notebook3.GetSelection()
self.Notebook3.DeletePage(page_to_delete)
def onButtonInsert(self, event):
self.addPage()
def onButtonMessage(self, event):
self.Notebook3.StaticText(0).AppendText("Yeah right. Like this works")
if __name__ == "__main__":
app = wx.App()
MainFrame().Show()
app.MainLoop()
我似乎无法将它完全正确地组合在一起。任何帮助表示赞赏。