Python Forum
[PyGame] Help with Font size in Python-Raspi
Thread Rating:
  • 2 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Help with Font size in Python-Raspi
#4
what did you set your text sizes to so i can replicate?

I am not sure what all the possible outcome text could be from that...but your positioning of your text objects is over complex than what it should be. A proper text object position to the center would be using the screen's rect center attribute. And if you had too much you would need to account for line wrapping, or always use two lines for simplicity.

I have more of a feeling its hard coding text positions when you dont know the size dimensions yet such as:
Quote:
      text_pos = text.get_rect(); text_pos.y = pos2; text_pos.x = 118
...
    pos+=65
    pos2+=65
...
      text_pos = text.get_rect(); text_pos.y = pos; text_pos.x = 98
...
    text_pos.x = 15
This first line places the drawing x position at 118 pixels...but you dont account for the width of the text. So you are just arbitrarily drawing it on the screen somewhere if you change the text sizes.

The proper way to handle text objects positioning. You dont need to do anyhting other than text_rect.center = screen_rect.center
have all your string as text, text_rect is your rect of the current text updated every frame, and draw that object to the center of the screen. Then it wouldnt matter what size the text is.

This doesnt change the size of the text,  but it does change the text string itself. And it would do the same if the size was changed each time. The text object is always centered on the screen. Regardless of whether the string is 1 digit or 10 digits, size of text, font style, etc.
https://github.com/metulburr/pygame_code...r_timed.py

To be honest your whole code is quite sloppy. If i did it i would replace 90% of your code. You should use format method instead of concatenating strings. I would use a class for the number to clean up some of the code.
Recommended Tutorials:
Reply


Messages In This Thread
RE: Help with Font size in Python-Raspi - by metulburr - Jan-24-2017, 01:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python code for alignment and font size 1418 0 391 Jan-14-2024, 03:56 AM
Last Post: 1418
  How to do "fixed size" (wrapping) math in Python? AlexanderWulf 13 2,158 Jul-19-2023, 04:13 PM
Last Post: deanhystad
Question Opening small size browser with python selenium not work, need help greenpine 0 1,671 Feb-07-2022, 11:36 AM
Last Post: greenpine
  How to set Tab size to 4 in Python interpreter? zzzhhh 1 1,927 Jan-18-2022, 12:11 PM
Last Post: snippsat
  Load external font and does not show font in the window ATARI_LIVE 16 8,491 Feb-05-2021, 10:36 PM
Last Post: EthanPayne
  Raspi Commands via Python (VS Code) Script AS4188 5 2,915 Oct-21-2020, 03:49 PM
Last Post: AS4188
  how to compare two different size images in python and find corresponding pixel value squidsirymchenry 1 4,666 Feb-03-2020, 06:48 AM
Last Post: michael1789
  size of set vs size of dict zweb 0 2,206 Oct-11-2019, 01:32 AM
Last Post: zweb
  Python function call font color JeffR1992 1 3,472 Apr-17-2019, 06:38 AM
Last Post: perfringo
  Is there a way to detect the text font, size and color from an image in python? Maia07 2 8,815 Aug-23-2018, 01:16 PM
Last Post: Maia07

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020