¿Cómo cambiar el color y el tamaño de la etiqueta de wx.sbSizer en Python?
Estoy creando una interfaz gráfica de usuario (GUI) y estoy usando varios wx.sbSizer para agrupar los widgets. Sin embargo, necesito cambiar la fuente y el color de la etiqueta wx.sbSizer (‘MyApp’) y aunque he buscado, no puedo encontrar cómo hacerlo.
Aquí tienes un ejemplo mínimo de trabajo:
class MyFrame ( wx.Frame ):
def init ( self, parent ):
wx.Frame.init ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
bSizer1 = wx.BoxSizer( wx.VERTICAL )
self.m_panel31 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
bSizer1_2 = wx.BoxSizer( wx.VERTICAL )
sbSizer1_2_1 = wx.StaticBoxSizer( wx.StaticBox( self.m_panel31, wx.ID_ANY, u”MyApp” ), wx.VERTICAL )
self.m_button6 = wx.Button( sbSizer1_2_1.GetStaticBox(), wx.ID_ANY, u”1″, wx.DefaultPosition, wx.DefaultSize, 0 )
sbSizer1_2_1.Add( self.m_button6, 0, wx.ALL, 5 )
self.m_button7 = wx.Button( sbSizer1_2_1.GetStaticBox(), wx.ID_ANY, u”2″, wx.DefaultPosition, wx.DefaultSize, 0 )
sbSizer1_2_1.Add( self.m_button7, 0, wx.ALL, 5 )
bSizer1_2.Add( sbSizer1_2_1, 1, wx.EXPAND, 5 )
self.m_panel31.SetSizer( bSizer1_2 )
self.m_panel31.Layout()
bSizer1_2.Fit( self.m_panel31 )
bSizer1.Add( self.m_panel31, 1, wx.EXPAND |wx.ALL, 5 )
self.SetSizer( bSizer1 )
self.Layout()
self.Centre( wx.BOTH )
def del ( self ):
pass
if name == “main“:
app = wx.App(redirect=False)
frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show(True)
app.MainLoop()
Gracias de antemano por cualquier ayuda.
davy.ai
Puede cambiar la fuente y el color de la etiqueta wx.sbSizer utilizando los métodos SetFont y SetForegroundColour. Por ejemplo, para cambiar la fuente a negrita y el color a rojo, puede añadir el siguiente código a su método init:
python
sbSizer1_2_1.GetStaticBox().SetFont(wx.Font(wx.FontInfo(14).Bold()))
sbSizer1_2_1.GetStaticBox().SetForegroundColour(wx.RED)
Esto debería cambiar la fuente y el color de la etiqueta wx.sbSizer.