InGame is a lightweight Python library designed to simplify making amazing UIs within a basic GUI window using tkinter
. It enables developers to easily register and trigger events based on key presses with clean, decorator-based syntax.
- ✅ Decorator-based event binding
- ✅ Enum-based key recognition (A–Z, arrows, Enter, Escape, etc.)
- ✅ Clean and extensible architecture
- ✅ Simple GUI rendering using
tkinter
Use pip install ingame
to install the project.
from ingame.core import InGame, Screen, EventType
from ingame.objects import Text, Button, Input
app = InGame()
@app.event(type=EventType.Key.A)
def handle_a():
print("Key A pressed!")
@app.event(type=EventType.Key.ESCAPE)
def handle_escape():
print("Escape pressed!")
screen.quit()
screen = Screen(app, title="My InGame App", width=600, height=400)
screen.set_resize(True, True)
hello_text = Text(screen, text="Hello!")
Button(screen, text="Click me", command=hello_text.destroy)
ht_input = Input(screen, packargs={"pady": 10})
def ht_click() -> None:
print(ht_input.get())
Button(screen, text="Print input value", command=ht_click, packargs={"pady": 10})
screen.show()
Supported via EventType.Key
, including:
- A–Z
- Arrow keys:
UP
,DOWN
,LEFT
,RIGHT
ENTER
,ESCAPE
,BACKSPACE
Handles registering and triggering events:
@event(type: EventType.Key)
: Registers a function for a specific key event.trigger_event(type)
: Manually triggers an event.
Simple tkinter
window with key event binding:
show()
: Opens the window and starts listening for key presses.quit()
: Closes the window.
InGameException
: Raised for invalid usage such as missing event type or unregistered keys.
Written in Python 3.10+
Uses tkinter
, Enum
, and inspect
.
Pull requests are welcome. For major changes, please open an issue first to discuss what you’d like to change.
Made with ❤️ by Natuworkguy