Connecting Tech Pros Worldwide Help | Site Map

setting font using wx.

Newbie
 
Join Date: Oct 2007
Posts: 28
#1: Aug 19 '09
I have the following code snippet from a larger program which is working perfectly for making a gui and adding buttons to it:
Expand|Select|Wrap|Line Numbers
  1.  
  2. self.B0 = wx.Button(id=wxID_FRAME2B0, label='Choose Cases', 
  3.          name='B0', parent=self, pos=wx.Point(300, 50), 
  4.          size=wx.Size(400, 50),style=0)
  5. 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.
bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,561
#2: Aug 19 '09

re: setting font using wx.


What specific error message do you receive? To access a font that is accessible to the underlying system:
Expand|Select|Wrap|Line Numbers
  1. wx.Font(pointSize, family, style, weight)
Try providing a style argument.
Newbie
 
Join Date: Oct 2007
Posts: 28
#3: Aug 19 '09

re: setting font using wx.


Okay i added it to the code like so:

Expand|Select|Wrap|Line Numbers
  1. self.B1 = wx.Button(id=wxID_FRAME2B1, label='Ratings/RXB',
  2.            name='B1', parent=self, pos=wx.Point(100, 375), 
  3.            size=wx.Size(90,25), style=0, 
  4.            font=wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL))
  5. 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)?
bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,561
#4: Aug 19 '09

re: setting font using wx.


Try using the SetFont() button method.
Expand|Select|Wrap|Line Numbers
  1. self.B1.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL))
Newbie
 
Join Date: Oct 2007
Posts: 28
#5: Aug 19 '09

re: setting font using wx.


ok i tried that but now i am getting this

AttributeError: 'Frame2' object has no attribute 'B1'

Expand|Select|Wrap|Line Numbers
  1.         self.B1.SetFont(wx.Font(12, wx.SWITSS, wx.NORMAL, wx.NORMAL))
  2.         self.B1 = wx.Button(id=wxID_FRAME2B1, label='Ratings/RXB',
  3.               name='B1', parent=self, pos=wx.Point(100, 375), size=wx.Size(90,25), style=0)
  4.         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 ?
bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,561
#6: Aug 19 '09

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
#7: Aug 19 '09

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. :)
bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,561
#8: Aug 19 '09

re: setting font using wx.


No problem. I am glad I could help. :)

-BV
Reply