A UIKit for Pygame
Project description
Getting Started
pip install PygameUIKit
Easy to use
import pygame
from PygameUIKit import Group, button, slider
W = 800
H = 600
class MyGame:
def __init__(self):
# You class code here
self.window = pygame.display.set_mode((W, H), pygame.RESIZABLE)
# Ui
self.ui = Group() # Create a group to hold all the ui elements. This is filled with the ui elements below thanks to the ui_group parameter
self.btn_start = button.ButtonText("Start",
self.start,
rect_color=(85, 145, 92),
fixed_width=200,
border_radius=10,
text_align="center",
ui_group=self.ui)
self.btn_quit = button.ButtonText("Quit", self.quit,
rect_color=(181, 71, 71),
fixed_width=180,
border_radius=10,
text_align="center",
ui_group=self.ui)
def run(self):
while True: # Game loop
# Your game code here
# Ui
# Handle events
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
pygame.quit()
self.ui.handle_event(event) # Handle the events for all the ui elements
# Draw
self.window.fill((0, 0, 0))
self.btn_start.draw(self.window, *self.btn_start.surface.get_rect(center=(W // 2, H // 2 - 50)).topleft)
self.btn_quit.draw(self.window, *self.btn_quit.surface.get_rect(center=(W // 2, H // 2 + 50)).topleft)
pygame.display.flip()
def start(self):
print("Starting")
def quit(self):
print("Quitting")
pygame.quit()
if __name__ == "__main__":
pygame.init()
MyGame().run()
Just put all your ui elements in a group and call group.handle_event(event).
You will have to draw the elements yourself with element.draw(win, x, y).
That is because you might want to have a custom layout where the x and y coordinates are calculated on the fly.
Available elements
- Buttons
button.ButtonTextbutton.ButtonImagebutton.ButtonImageTextbutton.ButtonPngIconbutton.ButtonTwoStatesbutton.ButtonThreadText
- Slider
- ComboBox
- TextInput
- Label
- BarChart
And more to come :)
Contributing
Feel free to do a pull request if you want to add a new element or improve the code.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file PygameUIKit-0.1.1.tar.gz.
File metadata
- Download URL: PygameUIKit-0.1.1.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
826ed450886b38c95f74965605290e82cac98510db9550a26fbd78f571b293a8
|
|
| MD5 |
ba1026800381ed639f7646fa9c6f4491
|
|
| BLAKE2b-256 |
5cb081738f9b41a1f2bc59a8114f48d73247482e5b24ab6337f848ede631bf99
|
File details
Details for the file PygameUIKit-0.1.1-py3-none-any.whl.
File metadata
- Download URL: PygameUIKit-0.1.1-py3-none-any.whl
- Upload date:
- Size: 15.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f283c6bd71d3277319de929f6bab08f14d955f9973802c8ee75b36db9462ab0
|
|
| MD5 |
aa7beb801b8f789b5b26b9a8a9bbe2c2
|
|
| BLAKE2b-256 |
6822ffec80c42e5b1e61a4c4e64aa6436a037650e97a324a5eb5a30db83e719d
|