Skip to main content

Pygame Text Input - 0.1

Simple way to write text in pygame using your keyboard!


Bugme Not
(bugmenot)
Write text in pygame! This small module can be used to write text in pygame. It includes a blinking cursor that can be moved using the left and right arrow key as well as the home and the end button. You can also press any button for a little bit longer to make it re-enter itself many times a second. It is very easy to use, check out github for instructions! In case you are wondering why you should use this module instead of EzText? Because eztext is garbage code. EzText has about a hundred if-statemets that check for input like this: "if K_k in events and K_SHIFT in pygame_pressed: string += "K"". Apart from the fact that this is extremely ugly code, this makes it also only support ONE keyboard - probably the american one. All the others have wrong keys in them. This module here takes the "unicode" attribute provided by pygame events and thus supports ALL letters and character, exactly the way they appear on your keyboard, be it with "Shift" or "Ctrl+Alt" pressed at the same time.

Links

Home Page
https://github.com/NSasquatch/pygame-text-input

Releases

Pygame Text Input 0.1 — 14 Nov, 2016

Pygame.org account Comments

  • William Savage 2017-01-05 16:23:27

    Amazing module! Thank you very much, ive been using Eztext for my project and it hasnt been working very well. When i add your cxode from github and add the:
    if textinput.update(events):
    print(textinput.get_text())

    I get every key i pressed comes up twice, is their a way round this as it kind of ruins the module

    William Savage 2017-01-05 23:12:43

    I have solved this

    Matt 2017-01-08 02:36:46

    Could you possibly post how you solved it, in case anyone else comes here with the same problem?

    skrell 2017-03-23 13:34:20.126855

    I guess you forgot that evaluating "if textinput.update(events):" actually calls the function that implements your string. If you put textinput.update(events) elsewhere in your code it just does it twice.
  • William Savage 2017-01-05 16:27:58

    Also is there anywhere to have a pre-displayed text that user changes? Thanls

    William Savage 2017-01-05 16:35:18

    Apologies for the several requests but is there also a way to inhibit the max le;bth of the string like you can in EzText

  • Henry D 2017-03-20 19:45:08.229355

    Hey! does this allow for a text box to be blitted to the game display? i intend to use this as a user friendly input for a quiz, (non for profit of course) and was wondering if the text box can be blitted to a certain part of the screen(in my case the bottom middle of the game display) thanks in advance :)