How do I make a text box in pygame? [duplicate]

2019-08-25 01:10发布

问题:

This question already has an answer here:

  • How to create a text input box with pygame? 2 answers

So I’m new with pygame and I was wondering how do you make a basic text box

I know you have to create a window as so:

import pygame, sys
pygame.init()

screen= pygame.display.set_mode([800,600]) 
pygame.display.flip

but then I have no idea where to go from there

any help much appreciated :)

回答1:

PyGame is low-level library and it doesn't have widgets.

You can use other modules like PGU, OcempGUI or SGC. Most of them have examples.

Most of them use own event loop so you have to learn how to use it instead of loop while True:.

See more on PyGame page:

  • https://www.pygame.org/wiki/gui
  • https://www.pygame.org/tags/gui

BTW:

SGC doesn't use own event loop and it shows how to use it in own mailoop in Getting Started

PGU uses own event loop but it shows how to use it in own mainloop (only) in example 10