/pygame_textinput

A package to support text input in pygame

Primary LanguagePython

Input system support in Pygame

This is a library that supports input using IME and direct input in pygame.
(PygameでIMEや直接入力を支援するライブラリです)
As far as I can tell, you can type in English, Japanese, and Chinese.

install with pip

pip install git+https://github.com/DYGV/pygame_textinput.git

Usage of example

import sys

import pygame
from pygame_textinput.textinput import TextInput


def main():
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    text_box = TextInput(pygame.font.SysFont("yumincho", 30), (255, 0, 0))
    while True:
        events = pygame.event.get()
        for event in events:
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit(0)
            if event.type == pygame.USEREVENT:
                # 入力確定したテキスト
                print(event.Text)
        screen.fill((112, 225, 112))
        text_box.update(events)
        screen.blit(text_box.get_surface(), (10, 550))
        pygame.display.update()


if __name__ == "__main__":
    main()

In some environments, you can't use the "yumincho" font . Please refer to this page.

You can also type in Chinese if you set up your IME and specify the font.

↓ Microsoft IME(Japanese) 実行結果_jp

↓ Microsoft pinyin(Chinese) 実行結果_ch