我已经使用 wxFormBuilder 构建了一个 GUI,并希望将按钮动态添加到 GUI 中的 sizer。这是 wxFormBuilder 代码。
# -*- coding: utf-8 -*-
###########################################################################
## Python code generated with wxFormBuilder (version Jun 17 2015)
## http://www.wxformbuilder.org/
##
## PLEASE DO "NOT" EDIT THIS FILE!
###########################################################################
import wx
import wx.xrc
###########################################################################
## Class HighVoltage
###########################################################################
class HighVoltage ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 1031,530 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
self.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_ACTIVECAPTION ) )
bSizer84 = wx.BoxSizer( wx.VERTICAL )
self.m_panel70 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
bSizer85 = wx.BoxSizer( wx.HORIZONTAL )
self.m_staticText79 = wx.StaticText( self.m_panel70, wx.ID_ANY, u"HV Documentation", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_staticText79.Wrap( -1 )
self.m_staticText79.SetFont( wx.Font( 20, 70, 90, 92, False, "Century Gothic" ) )
bSizer85.Add( self.m_staticText79, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )
bSizer85.AddSpacer( ( 0, 0), 1, wx.EXPAND, 5 )
self.m_bitmap24 = wx.StaticBitmap( self.m_panel70, wx.ID_ANY, wx.Bitmap( u"LOGOtransSmall.png", wx.BITMAP_TYPE_ANY ), wx.DefaultPosition, wx.DefaultSize, 0 )
bSizer85.Add( self.m_bitmap24, 0, wx.ALL, 5 )
self.m_panel70.SetSizer( bSizer85 )
self.m_panel70.Layout()
bSizer85.Fit( self.m_panel70 )
bSizer84.Add( self.m_panel70, 0, wx.EXPAND |wx.ALL, 5 )
self.m_panel71 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
bSizer86 = wx.BoxSizer( wx.VERTICAL )
bSizer86.AddSpacer( ( 0, 0), 1, wx.EXPAND, 5 )
self.m_panel73 = wx.Panel( self.m_panel71, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
bSizer86.Add( self.m_panel73, 0, wx.EXPAND |wx.ALL, 5 )
self.m_panel71.SetSizer( bSizer86 )
self.m_panel71.Layout()
bSizer86.Fit( self.m_panel71 )
bSizer84.Add( self.m_panel71, 1, wx.EXPAND |wx.ALL, 5 )
self.m_panel72 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
bSizer87 = wx.BoxSizer( wx.HORIZONTAL )
bSizer87.AddSpacer( ( 0, 0), 1, wx.EXPAND, 5 )
self.m_button65 = wx.Button( self.m_panel72, wx.ID_ANY, u"Exit", wx.DefaultPosition, wx.DefaultSize, 0 )
bSizer87.Add( self.m_button65, 0, wx.ALL, 5 )
self.m_panel72.SetSizer( bSizer87 )
self.m_panel72.Layout()
bSizer87.Fit( self.m_panel72 )
bSizer84.Add( self.m_panel72, 0, wx.EXPAND |wx.ALL, 5 )
self.SetSizer( bSizer84 )
self.Layout()
self.Centre( wx.BOTH )
def __del__( self ):
pass
我想向 m_panel71 的子 bSizer86 添加按钮。这是我到目前为止所尝试的。
class HvDocs(HighVoltage):
def __init__(self, parent):
HighVoltage.__init__(self, parent)
con = sqlite3.connect('hsmanagement.sqlite')
cur = con.execute('SELECT employee FROM employees WHERE hv=1 ORDER BY employee')
result = cur.fetchall()
con.close()
print result
sizer = self.GetSizer()
print type(sizer)
for f in range(0, len(result) ):
sizer.Add(wx.Button(self, label=str(result[f][0]), id=int(f), size=(200, 40)), 2, wx.CENTER)
我已经尝试了一些sizer = self.GetSizer()
诸如此类的变体sizer = self.m_panel71
,sizer = self.GetSizer(self.m_panel71)
但我所能管理的就是将按钮添加到顶级大小调整器 bSizer84。如何访问 bSizer86?