0

Why my text not showing? Without any errors, still not showing.

Here is my code:

import pygame

size = width, height = (400, 300)
screen = pygame.display.set_mode(size)
pygame.init()


def draw():
    font = pygame.font.Font(None, 50)
    text = font.render("Hello pygame", True, (100, 255, 100))
    text_x = width // 2 - text.get_width() // 2
    text_y = height // 2 - text.get_height() // 2
    text_w = text.get_width()
    text_h = text.get_height()
    screen.blit(text, (text_x, text_y))
    pygame.draw.rect(screen, (0, 255, 0),
                     (text_x - 10, text_y - 10, text_w + 20, text_h + 20), 1)


draw()

while pygame.event.wait().type != pygame.QUIT:
    pygame.display.flip()

pygame.quit()

Result:

output

mkrieger1
  • 14,486
  • 4
  • 43
  • 54
  • 2
    Running your code copy and pasted exactly as it is gives [this](https://i.gyazo.com/5aeca9e3e39cc20de8270b27c0719fe1.png) which I am guessing is the expected output. What version of python and pygame are you using so I can change my environment? – Oddity Feb 07 '21 at 02:00
  • Yeah, my results are the same as @Oddity's results. – Ann Zen Feb 07 '21 at 02:02
  • @Oddity pygame 2.0.1 (SDL 2.0.14, Python 3.9.1) – alseit_01 Feb 07 '21 at 02:02
  • @alseit_01 Yeah I copy pasted the code and I have the exact same pygame version – Aditya Gupta Feb 07 '21 at 02:05
  • @AdityaGupta Do you have python 3.9.1? – Oddity Feb 07 '21 at 02:06
  • @alseit_01 Yes I have Python 3.9.1 with Pygame 2.0.1 (SDL 2.0.14, Python 3.9.1) – Aditya Gupta Feb 07 '21 at 02:08
  • @AdityaGupta Yea I just installed 3.9.1 and the same pygame version and I am still getting the correct output... Let me try this on my macbook see if that has something to do with it. – Oddity Feb 07 '21 at 02:09
  • that is strange) – alseit_01 Feb 07 '21 at 02:09
  • @Oddity ok, keep me in touch – alseit_01 Feb 07 '21 at 02:11
  • @alseit_01 So I tried this on my macbook pro 2019 with the same versions that you have and your problem shows. After searching I found [this article](https://stackoverflow.com/questions/52718921/problems-getting-pygame-to-show-anything-but-a-blank-screen-on-macos) and after following the guide in the selected answer your problem no longer shows on my macbook. Let me know if this helps! – Oddity Feb 07 '21 at 02:14

0 Answers0