Python Forum
[pyGame] Text with Input, help needed !
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[pyGame] Text with Input, help needed !
#1
Hey Game Programmers and Software Developers...

I try to create tekst with an input, so you can typ any thing on your keyboard,
and it render into the pygame window... but it don't works...

This is my script:

import pygame
import sys

pygame.init()

WHITE = (255, 255, 255)
RED = (0, 255, 0)
BLACK = (0, 0, 0)

size = (640, 480)
screen = pygame.display.set_mode(size)

pygame.display.set_caption("JCads Develop")


done = False
clock = pygame.time.Clock()
  
while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                done = True

    
          
    screen.fill(WHITE)
    pygame.draw.line(screen, RED, [0, 0], [100, 100], 5)

    font = pygame.font.SysFont('Calibri', 25, True, False)
    text = font.render(input("Your Name: "), True, BLACK)
    screen.blit(text, [250, 250])
    
    pygame.display.flip()

    clock.tick(60)
pygame.quit()
sys.exit()
Can anyone help me to give an example, about how i can give text an input, just an player
or user of my program can input the text from the keyboard ?...

Thanks for help, Jamie.
Reply
#2
Quote:I try to create tekst with an input, so you can typ any thing on your keyboard,
and it render into the pygame window... but it don't works...
What do you mean by it doesnt work?!? If i run your script i can change the text each time i press enter. What do you want it to do?

P.S. Taking input from terminal/command prompt in A GUI program is bad. Its as bad as have time.sleep() in a GUI program. None of that should be there as it halts the updates to drawing to the screen as well. It would be better to build an input box and button like a GUI toolkit.

This is basically a wrapper around mekires code, i just cant find his repo at the moment. But this has just the button and input box.
https://github.com/metulburr/pygooey
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [pyGame] More Text in one Window, example needed ! JamieVanCadsand 1 3,539 Oct-03-2017, 03:42 PM
Last Post: metulburr
  [pyGame] How do i change text with keyboard ?... JamieVanCadsand 1 4,532 Oct-03-2017, 10:05 AM
Last Post: metulburr
  [pyGame] Render Text from Variable, examples needed ! JamieVanCadsand 1 5,929 Oct-03-2017, 09:54 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020