Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lebogoo/pygametext
This Package adds UI Elements like Buttons and Textboxes to PyGame.
https://github.com/lebogoo/pygametext
Last synced: about 1 month ago
JSON representation
This Package adds UI Elements like Buttons and Textboxes to PyGame.
- Host: GitHub
- URL: https://github.com/lebogoo/pygametext
- Owner: LeBogoo
- License: gpl-3.0
- Created: 2020-02-28T11:19:33.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-08T16:28:43.000Z (almost 5 years ago)
- Last Synced: 2024-11-09T18:12:06.094Z (about 2 months ago)
- Language: Python
- Size: 31.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
### Changelog:
* Fixed Bugs
* Added pgt.square() function (for more information look at the Elements section)# pygametext
This Package adds UI Elements to PyGame.## Install
pip install pygametext## Import
`import pygametext`## Initiate pygametext
`pgt = pygametext.PGT(screen)`## Elements
`pgt.button(x,y,width,height,buttonColor,"Text",textColor,onClickFunction,onClickArguments,layer)`
-> Returns True`pgt.switch(x,y,width,height,buttonColor,"Text",textColor,activeFunction,activeArguments,layer)`
-> Returns True`pgt.checkbox(x,y,scale,color,activeFunction,activeArguments,layer)`
-> Returns True`pgt.text(x,y,"Text",textColor,textSize,layer)`
-> Returns True`pgt.square(x,y,width,height,color,layer)`
-> Returns True`pgt.textbox(x,y,width,height,textColor,layer)`
-> Returns True## Process inputs and events
This function needs to be called if you want that the elements on specified layer to be interactive.
`pgt.update(layer)`## Draw elements to screen
This function needs to be called if you want that the elements on specified layer to be drawn.
`pgt.draw(layer)`## Utitilty functions
`pgt.getLayer(layer)`
-> Returns list of PGT Objects on specified Layer`pgt.clear(id,layer)`
-> Returns True or False`pgt.rebuild(layer)`
-> Returns True``` python
import pygame
import pygametextrunning = True
pygame.init()
screen = pygame.display.set_mode((640, 360))
clock = pygame.time.Clock()pgt = pygametext.PGT(screen) # Define pygametext object.
pgt.button(10,10,100,50,(255,0,0),"Hello!",(0,0,0),print,"Hello World!",0) # Add pgt Button
pgt.button(120,10,100,50,(255,255,0),"Bye bye",(0,0,0),print,"Goodbye World!",0) # Add pgt Button
pgt.text(10,70,"Simple pygametext example.",(0,120,0),20,0) # Add pgt Textdef update(): # Update & Eventd
events = pygame.event.get()pgt.update(events, 0) # Update all pgt elements from layer 0. Takes events arg to process some elements.
for event in events:
if event.type == pygame.QUIT:
running = False
pygame.quit()
quit()def draw():
screen.fill((255,255,255)) # Clear screen
pgt.draw() # Draw all pgt elements from layer 0
pygame.display.flip()while running:
update()
draw()
clock.tick(60)
```