I’m creating a GUI and I’m using several wx.sbSizer to group the widgets. However I need to change the font and the color of the wx.sbSizer Label (‘MyApp’) and although I have searched I cannot find out how to do it.
Here’s a minimal working example:
JavaScript
x
45
45
1
class MyFrame ( wx.Frame ):
2
3
def __init__( self, parent ):
4
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 )
5
6
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
7
8
bSizer1 = wx.BoxSizer( wx.VERTICAL )
9
10
self.m_panel31 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
11
bSizer1_2 = wx.BoxSizer( wx.VERTICAL )
12
13
sbSizer1_2_1 = wx.StaticBoxSizer( wx.StaticBox( self.m_panel31, wx.ID_ANY, u"MyApp" ), wx.VERTICAL )
14
15
self.m_button6 = wx.Button( sbSizer1_2_1.GetStaticBox(), wx.ID_ANY, u"1", wx.DefaultPosition, wx.DefaultSize, 0 )
16
sbSizer1_2_1.Add( self.m_button6, 0, wx.ALL, 5 )
17
18
self.m_button7 = wx.Button( sbSizer1_2_1.GetStaticBox(), wx.ID_ANY, u"2", wx.DefaultPosition, wx.DefaultSize, 0 )
19
sbSizer1_2_1.Add( self.m_button7, 0, wx.ALL, 5 )
20
21
22
bSizer1_2.Add( sbSizer1_2_1, 1, wx.EXPAND, 5 )
23
24
25
self.m_panel31.SetSizer( bSizer1_2 )
26
self.m_panel31.Layout()
27
bSizer1_2.Fit( self.m_panel31 )
28
bSizer1.Add( self.m_panel31, 1, wx.EXPAND |wx.ALL, 5 )
29
30
31
self.SetSizer( bSizer1 )
32
self.Layout()
33
34
self.Centre( wx.BOTH )
35
36
def __del__( self ):
37
pass
38
39
if __name__ == "__main__":
40
app = wx.App(redirect=False)
41
frame = MyFrame(None)
42
app.SetTopWindow(frame)
43
frame.Show(True)
44
app.MainLoop()
45
Thank you in adavnce for any help.
Advertisement
Answer
You are already using sbSizer1_2_1.GetStaticBox()
to access the box within the sizer.
Simply use that to get the box, then utilise the methods available for that widget, see below:
JavaScript
1
49
49
1
import wx
2
class MyFrame ( wx.Frame ):
3
4
def __init__( self, parent ):
5
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 )
6
7
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
8
9
bSizer1 = wx.BoxSizer( wx.VERTICAL )
10
11
self.m_panel31 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
12
bSizer1_2 = wx.BoxSizer( wx.VERTICAL )
13
14
sbSizer1_2_1 = wx.StaticBoxSizer( wx.StaticBox( self.m_panel31, wx.ID_ANY, u"MyApp" ), wx.VERTICAL )
15
16
# Get the box and then set the colour and font
17
sb = sbSizer1_2_1.GetStaticBox()
18
sb.SetBackgroundColour('lightgreen')
19
font = wx.Font(16, wx.ROMAN, wx.ITALIC, wx.NORMAL)
20
sb.SetFont(font)
21
22
self.m_button6 = wx.Button( sbSizer1_2_1.GetStaticBox(), wx.ID_ANY, u"1", wx.DefaultPosition, wx.DefaultSize, 0 )
23
sbSizer1_2_1.Add( self.m_button6, 0, wx.ALL, 5 )
24
25
self.m_button7 = wx.Button( sbSizer1_2_1.GetStaticBox(), wx.ID_ANY, u"2", wx.DefaultPosition, wx.DefaultSize, 0 )
26
sbSizer1_2_1.Add( self.m_button7, 0, wx.ALL, 5 )
27
28
bSizer1_2.Add( sbSizer1_2_1, 1, wx.EXPAND, 5 )
29
30
self.m_panel31.SetSizer( bSizer1_2 )
31
self.m_panel31.Layout()
32
bSizer1_2.Fit( self.m_panel31 )
33
bSizer1.Add( self.m_panel31, 1, wx.EXPAND |wx.ALL, 5 )
34
35
self.SetSizer( bSizer1 )
36
self.Layout()
37
38
self.Centre( wx.BOTH )
39
40
def __del__( self ):
41
pass
42
43
if __name__ == "__main__":
44
app = wx.App(redirect=False)
45
frame = MyFrame(None)
46
app.SetTopWindow(frame)
47
frame.Show(True)
48
app.MainLoop()
49