读书人

【python】多标签记事簿

发布时间: 2013-07-01 12:33:04 作者: rapoo

【python】多标签记事本
我想搞个多标签的记事本,在点新建时打开一个新的标签页面。但是现在新建后无法显示新的标签页。可能是布局问题。
点击新键菜单后会进入newtab()函数。请帮忙看看应该怎么写,谢谢

class NotBookMainFrame(wx.Frame):
def __init__(self,parent,title):
self.hbox = wx.BoxSizer(wx.HORIZONTAL)
#目录树
self.dir = wx.GenericDirCtrl(self.panel, -1,dir="D:",size=(200,810),style=0)
self._tree=self.dir.GetTreeCtrl()

self.notebook = fnb.FlatNotebook(self.panel,-1,agwStyle = fnb.FNB_X_ON_TAB)
self.control = wx.stc.StyledTextCtrl(self.notebook,style=wx.TE_MULTILINE|wx.TE_LINEWRAP)
self.control.SetCaretLineVisible(True)
self.control.SetCaretLineBack("yellow")
self.notebook.AddPage(self.control,'title_1',True)

self.hbox.Add(self._tree,0,wx.EXPAND,1)
self.hbox.Add(self.notebook,0,flag=wx.EXPAND | wx.LEFT)
#self.newtab()
self.panel.SetSizer(self.hbox)
self.dir.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnOpen_2)

self.Maximize()
self.Show(True)

#新建标签函数
def newtab(self):
#多tab页
self.notebook2 = fnb.FlatNotebook(self.panel,-1,agwStyle = fnb.FNB_X_ON_TAB)
self.control2 = wx.stc.StyledTextCtrl(self.notebook2,style=wx.TE_MULTILINE|wx.TE_LINEWRAP)
self.control2.SetCaretLineVisible(True)
self.control2.SetCaretLineBack("yellow")
self.notebook2.AddPage(self.control2,'title_2',True)
self.hbox.Add(self.notebook2,1,flag=wx.EXPAND)
self.panel.SetSizer(self.hbox)
[解决办法]
你的代码里,每次执行newtab会生成一个新的notebook这样不对,用原来__init__里的那个notebook就行,类似...

def newtab(self):
#多tab页
control = wx.stc.StyledTextCtrl(self.notebook)
control.SetCaretLineVisible(True)
control.SetCaretLineBack("yellow")
self.notebook.AddPage(control,'title_xxx',True)


[解决办法]
def OnCloseWindow(self, event):
try:
self.asciiframe.Destroy()
except:
pass
self.Destroy()

读书人网 >perl python

热点推荐