Skip to main content

Fixes text-centering issues in pygame!.

Project description

Pygame

PYGAME WITH TRUE CENTERING

Shell

pip install pygame-text-centering

Python

#example.py

import pygame
from pgcentering import Button, BadButton, Text, TextButton

if __name__ == "__main__":
    
    pygame.init()
    clock = pygame.time.Clock()

    screen_dim = (800, 400)
    screen = pygame.display.set_mode(screen_dim)
    button_color = (200, 200, 200)
    button_dim = (300, 100)

    good_button_center = (screen_dim[0]//4, screen_dim[1]//4)
    good_button = Button(
        screen = screen,
        text = 'GOOD', 
        color = button_color, 
        center = good_button_center, 
        dim = button_dim)
    good_button.draw()

    bad_button_center = (screen_dim[0]*3//4, screen_dim[1]//4)
    bad_button = BadButton(
        screen = screen, 
        text = 'BAD', 
        color = button_color, 
        center = bad_button_center, 
        dim = button_dim)
    bad_button.draw()

    plain_text_center = (screen_dim[0]//4, screen_dim[1]*3//4)
    plain_text = Text(
        screen = screen,
        text = 'BUTTON',
        color = button_color,
        center = plain_text_center,
        font_size = 70)
    plain_text.draw()
    
    text_button_center = (screen_dim[0]*3//4, screen_dim[1]*3//4)
    text_button = TextButton(
        screen = screen,
        text = 'TEXT',
        color = button_color,
        center = text_button_center,
        font_size = 70)
    text_button.draw()

    while True:

        if good_button.is_clicked():
            print("I am a good button")

        if bad_button.is_clicked():
            print("I am a bad button")

        if text_button.is_clicked():
            print("I am a text button")
            text_button.erase_button()

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                exit()
                
        clock.tick(60)
        pygame.display.update()

WHAT A DIFFERENCE!

Button Demo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygame-text-centering-0.1.tar.gz (4.5 kB view details)

Uploaded Source

File details

Details for the file pygame-text-centering-0.1.tar.gz.

File metadata

  • Download URL: pygame-text-centering-0.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for pygame-text-centering-0.1.tar.gz
Algorithm Hash digest
SHA256 52201a39afb6ae46ea9a9ea5af5c1b838b09ffaae24e4de22cf3aba2bd572083
MD5 4e714fdfc90b1646836072984ff12d16
BLAKE2b-256 63a20c4095d373214cea56978d9fabfdce37140e3d3ef71cc3df5fa9d190f4b3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page