我试图创建一个面板并试图在面板中添加几个按钮,但是为了某些原因,只显示“添加”按钮,
import wx
class MyPanel(wx.Panel):
def __init__(self,parent, id, pos,size, style):
wx.Panel.__init__(self,parent,id,pos,size,style)
self.BackgroundColour = 'RED'
hbox1 = wx.BoxSizer(wx.HORIZONTAL)
hbox1.Add(wx.Button(self,label="Add"),flag=wx.LEFT)
#hbox1.Add((-1,10))
hbox1.Add(wx.Button(self,label="Update"),flag=wx.RIGHT)
#hbox1.Add(wx.Button(self,label="Delete"),flag=wx.LEFT, border=20)
#hbox1.Add(wx.Button(self,label="Add"),flag=wx.LEFT, border=20)
#hbox1.Add(wx.Button(self,label="Update"),flag=wx.LEFT, border=20)
#hbox1.Add(wx.Button(self,label="Delete"),flag=wx.LEFT, border=20)
class MyTreeCtrl(wx.TreeCtrl):
def __init__(self, parent, id, pos, size, style):
wx.TreeCtrl.__init__(self, parent, id, pos, size, style)
class Example(wx.Frame):
def __init__(self, parent, title):
super(Example, self).__init__(parent, title=title, size=(700, 700))
panel = wx.Panel(self)
panel.SetBackgroundColour('#4f5049')
vbox = wx.BoxSizer(wx.HORIZONTAL)
tID = wx.NewId()
self.tree = MyTreeCtrl(panel,tID,wx.DefaultPosition,wx.DefaultSize,wx.TR_HAS_BUTTONS)
tID = wx.NewId()
self.lefthandpanel = MyPanel(panel,tID,wx.DefaultPosition,wx.DefaultSize,wx.TR_HAS_BUTTONS)
vbox.Add(self.tree, 1, wx.EXPAND | wx.ALL, 20)
vbox.Add(self.lefthandpanel, 1, wx.EXPAND | wx.ALL, 20)
panel.SetSizer(vbox)
isz = (16,16)
il = wx.ImageList(isz[0], isz[1])
fldridx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, isz))
fldropenidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, isz))
fileidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, isz))
self.tree.SetImageList(il)
self.il = il
# NOTE: For some reason tree items have to have a data object in
# order to be sorted. Since our compare just uses the labels
# we don't need any real data, so we'll just use None below for
# the item data.
self.root = self.tree.AddRoot("The Root Item")
self.tree.SetPyData(self.root, None)
self.tree.SetItemImage(self.root, fldridx, wx.TreeItemIcon_Normal)
self.tree.SetItemImage(self.root, fldropenidx, wx.TreeItemIcon_Expanded)
for x in range(15):
child = self.tree.AppendItem(self.root, "Item %d" % x)
self.tree.SetPyData(child, None)
self.tree.SetItemImage(child, fldridx, wx.TreeItemIcon_Normal)
self.tree.SetItemImage(child, fldropenidx, wx.TreeItemIcon_Expanded)
for y in range(5):
last = self.tree.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)))
self.tree.SetPyData(last, None)
self.tree.SetItemImage(last, fldridx, wx.TreeItemIcon_Normal)
self.tree.SetItemImage(last, fldropenidx, wx.TreeItemIcon_Expanded)
for z in range(5):
item = self.tree.AppendItem(last, "item %d-%s-%d" % (x, chr(ord("a")+y), z))
self.tree.SetPyData(item, None)
self.tree.SetItemImage(item, fileidx, wx.TreeItemIcon_Normal)
#self.tree.SetItemImage(item, smileidx, wx.TreeItemIcon_Selected)
print self.tree
self.Centre()
self.Show()
if __name__ == '__main__':
app = wx.App()
Example(None,title="Border")
app.MainLoop()
答案 0 :(得分:0)
在self.SetSizer(hbox1)
构造函数中添加按钮后添加MyPanel
。这样您就可以告诉面板使用布局。