setting font using wx.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fahadqureshi
    New Member
    • Oct 2007
    • 28

    setting font using wx.

    I have the following code snippet from a larger program which is working perfectly for making a gui and adding buttons to it:
    Code:
            
    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.
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    What specific error message do you receive? To access a font that is accessible to the underlying system:
    Code:
    wx.Font(pointSize, family, style, weight)
    Try providing a style argument.

    Comment

    • fahadqureshi
      New Member
      • Oct 2007
      • 28

      #3
      Okay i added it to the code like so:

      Code:
      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)?

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        Try using the SetFont() button method.
        Code:
        self.B1.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL))

        Comment

        • fahadqureshi
          New Member
          • Oct 2007
          • 28

          #5
          ok i tried that but now i am getting this

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

          Code:
                  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 ?

          Comment

          • bvdet
            Recognized Expert Specialist
            • Oct 2006
            • 2851

            #6
            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

            Comment

            • fahadqureshi
              New Member
              • Oct 2007
              • 28

              #7
              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. :)

              Comment

              • bvdet
                Recognized Expert Specialist
                • Oct 2006
                • 2851

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

                -BV

                Comment

                Working...