1

enter image description hereHow I can get width of pygame bar? I mean the gray taskbar. I've tried to to following but it does not work properly.

import pygame

pygame.init()
disp = pygame.display.set_mode((640, 480))
disp.fill((0, 0, 0))
pygame.display.flip()
title = 'text'
pygame.display.set_caption(title)

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()

But the text is positioned to the left side. I I use pygame.display.set_caption(f"{title: > 320}") it goes out of window.

Try to figure how to get width of the bar and then position text to center.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
contelo
  • 11
  • 2

1 Answers1

0

You Can get the the bar width Beacause Bar Width = Screen width. and this code is how i put the text in the center

import pygame

pygame.init()
ScreenWidth,ScreenHight = 640, 480
disp = pygame.display.set_mode((ScreenWidth, ScreenHight))
disp.fill((0, 0, 0))
pygame.display.flip()
title = 'textdd'
spaces = " "
spacecount = (round(640/7)-(len(title)))

print(spacecount)

for c in range(spacecount):
    spaces = ' '+spaces

pygame.display.set_caption(spaces+title)

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()