AustL / PygameWidgets

A module for use with Pygame. Includes fully customisable buttons, textboxes, sliders and many more, as well as the ability to create and run animations on these widgets.
MIT License
57 stars 16 forks source link

Set the font and font size with ButtonArray? #18

Closed deegquest closed 3 years ago

deegquest commented 3 years ago

Is it possible to set the font and font size with ButtonArray?

AustL commented 3 years ago

Yes. To do so, just pass in a tuple into the constructor with keyword argument 'fonts'. E.g.

ButtonArray(win, x, y, width, height, shape, fonts=('font1', 'font2', 'font3'))) for a button array with 3 buttons. The same applies for fontSizes. Currently, if all the buttons have the same properties, you need to repeat. This may be fixed later.

deegquest commented 3 years ago

Thanks, I will try it when I get the chance.

deegquest commented 3 years ago

I got it to work, not with the font str name, but with the font object combined with the size (not a separate fontSizes=()). The below works: font1 = pygame.font.Font(pygame.font.match_font('arial'), 50) font2 = pygame.font.Font(pygame.font.match_font('impact'), 60) red = (200, 0, 0) green = (0, 40, 0) buttonArray = ButtonArray(win, 50, 50, 500, 500, (2, 2), border=100, texts=('1', '2', '3', '4'), fonts=(font1, font2, font1, font2), textColours=(red, green, red, green) )

AustL commented 3 years ago

I'm not sure why this is happening, but I will look into it.

AustL commented 3 years ago

The fonts keyword argument takes Font objects not strings. The fontSize keyword argument only applies for the default font and is overridden by the fonts provided.