setting font using wx. | Newbie | | Join Date: Oct 2007
Posts: 28
| |
I have the following code snippet from a larger program which is working perfectly for making a gui and adding buttons to it: -
-
self.B0 = wx.Button(id=wxID_FRAME2B0, label='Choose Cases',
-
name='B0', parent=self, pos=wx.Point(300, 50),
-
size=wx.Size(400, 50),style=0)
-
self.B0.Bind(wx.EVT_BUTTON, self.OnB0Button, id=wxID_FRAME2B0)
I have no problems setting up the buttons but am now trying to add a larger font size and different font style to it. I have tried using these to no avail:
font=wx.Font(25, wx.SWISS, wx.BOLD)
font=wx.SetFont(25, wx.SWISS, wx.BOLD)
The gui keeps crashing everytime i add one of these.
I have multiple buttons and would like one of them to have really big font but the others to have normal font.
Any help will be much appreciated.
|  | Moderator | | Join Date: Oct 2006 Location: Nashville, TN
Posts: 1,561
| | | re: setting font using wx.
What specific error message do you receive? To access a font that is accessible to the underlying system: - wx.Font(pointSize, family, style, weight)
Try providing a style argument.
| | Newbie | | Join Date: Oct 2007
Posts: 28
| | | re: setting font using wx.
Okay i added it to the code like so: - self.B1 = wx.Button(id=wxID_FRAME2B1, label='Ratings/RXB',
-
name='B1', parent=self, pos=wx.Point(100, 375),
-
size=wx.Size(90,25), style=0,
-
font=wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL))
-
self.B1.Bind(wx.EVT_BUTTON, self.OnB1Button, id=wxID_FRAME2B1)
the error i am getting is
TypeError: 'font' is an invalid keyword argument for this function
I think i am referencing it incorrectly. Does it need to be declared within the wx.Button() parameters or is it supposed to be declared outside and then referenced within wx.Button() using some shorter code like font=(font1)?
|  | Moderator | | Join Date: Oct 2006 Location: Nashville, TN
Posts: 1,561
| | | re: setting font using wx.
Try using the SetFont() button method. - self.B1.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL))
| | Newbie | | Join Date: Oct 2007
Posts: 28
| | | re: setting font using wx.
ok i tried that but now i am getting this
AttributeError: 'Frame2' object has no attribute 'B1' - self.B1.SetFont(wx.Font(12, wx.SWITSS, wx.NORMAL, wx.NORMAL))
-
self.B1 = wx.Button(id=wxID_FRAME2B1, label='Ratings/RXB',
-
name='B1', parent=self, pos=wx.Point(100, 375), size=wx.Size(90,25), style=0)
-
self.B1.Bind(wx.EVT_BUTTON, self.OnB1Button, id=wxID_FRAME2B1)
is there something specific about placement of the code? does it have to go somewhere specific or can it go anywhere before the button definition like i have it ?
|  | Moderator | | Join Date: Oct 2006 Location: Nashville, TN
Posts: 1,561
| | | re: setting font using wx.
You have to define self.B1 before you can use method self.B1.SetFont(). Think about it. How can you call a method of an object that does not exist?
-BV
| | Newbie | | Join Date: Oct 2007
Posts: 28
| | | re: setting font using wx.
AHHHHHHHHHHh i see. Thanks for your help. That was really stupid of me to not see that. Anyways I got it to work it needed to go after the button definition.
Thanks again. :)
|  | Moderator | | Join Date: Oct 2006 Location: Nashville, TN
Posts: 1,561
| | | re: setting font using wx.
No problem. I am glad I could help. :)
-BV
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,272 network members.
|