2019-03-30 03:38:31

So I need a way to get a message somebody types on the keyboard. The problem, I do not want to use the standard input function because it creates a separate window and it’s not very obvious to figure out.  So, any tips? People kept suggesting using something called tkinter on Google, but I couldn’t find a comprehensive installation guide for it.  Looking at the pygame documentation, it specifically warns against creating a function that checks for every single key on the keyboard. Besides,  that will be super annoying to create.  Oh, and before I forget, tkinter is not already installed on my machine, I tried importing it and got  module not found error.

2019-03-30 04:22:06 (edited by magurp244 2019-03-30 05:11:52)

Use event.unicode when the key is pressed, it won't handle special characters though. Example:

import pygame
import sys

def Example():
#initialize pygame
    pygame.init()
#create display
    window = pygame.display.set_mode([640,480])
#string to collect
    wing = ''

#main update loop
    while True:
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
            #add character to storage string
                wing += event.unicode
            #print string and clear it
                if event.key == pygame.K_RETURN:
                    print(wing)
                    if wing[:len(wing)-1] == "yes":
                        print("it works!")
                    wing = ''
                if event.unicode == "b":
                    print('you pressed b!')
            #if escape is pressed, clean up and quit
                if event.key == pygame.K_ESCAPE:
                    pygame.quit()
                    sys.exit(0)

    #update window
        pygame.display.update()

Example()
-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2019-03-30 17:39:56

Hi, use that dlg class from agk3.  it is on carter's github.

best regards
never give up on what ever you are doing.