Note that there are some explanatory texts on larger screens.

plurals
  1. POPyGame - cannot provide text on screen using blit() call
    primarykey
    data
    text
    <p>I am implementing a simple version of Hangman as a total beginner. </p> <p>In my code all text messages created inside the for-loop (<code>for event in pygame.event.get():</code>) are not shown on the screen. One can see, though, that they blink for a fraction of a second, where they should be, but they never fully show up.</p> <pre><code>bif = "bg.jpg" import pygame, sys, time from pygame.locals import * pygame.init() screen_widht = 600 screen_height = 300 user_guess = '' word = "fuzzy" guesses = 3 hidden_word = '-'*(len(word)) list_of_indexes = [] valid_letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] screen = pygame.display.set_mode((screen_widht, screen_height), 0, 32) background = pygame.image.load(bif).convert() font = pygame.font.Font(None, 20) text_color = (10, 10, 10) def find_indexes(s, ch): global list_of_indexes list_of_indexes = [i for i, ltr in enumerate(s) if ltr == ch] while True: screen.blit(background, (0, 0)) y = 10 msg1 = font.render("Welcome to Hangman!", 1, text_color) screen.blit(msg1, (10, y)) y += 20 msg2 = font.render("The word now looks like this: " + hidden_word, 1, text_color) screen.blit(msg2, (10, y)) y += 20 msg3 = font.render("You have " + str(guesses) + " guesses left", 1, text_color) screen.blit(msg3, (10, y)) y += 20 if guesses &gt; 0 and '-' in hidden_word: msg4 = font.render("Input your guess", 1, text_color) screen.blit(msg4, (10, y)) for event in pygame.event.get(): #there is the loop which does not blit messages on the screen if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYUP: key = event.key user_guess = chr(key) if user_guess not in valid_letters: msg5 = font.render("Input valid guess", 1, text_color) screen.blit(msg5, (10, 90)) else: msg7 = font.render("Your guess is " + user_guess, 1, text_color) screen.blit(msg7, (10, 90)) if event.type == KEYUP and user_guess not in word and guesses &gt; 0: guesses -= 1 if user_guess not in word: msg8 = font.render("There are no " + user_guess + "`s in this word", 1, text_color) screen.blit(msg8, (10, 110)) else: msg6 = font.render("Your guess is correct", 1, text_color) screen.blit(msg6, (10, 110)) find_indexes(word, user_guess) while len(list_of_indexes) &gt; 0: for ind in list_of_indexes: hidden_word = hidden_word[:ind] + user_guess + hidden_word[ind+1:] list_of_indexes.remove(ind) if guesses == 0 and '-' in hidden_word: msg9 = font.render("You are completely hung", 1, text_color) screen.blit(msg9, (10, 130)) if not '-' in hidden_word: msg10 = font.render("You guessed the word", 1, text_color) screen.blit(msg10, (10, 130)) pygame.display.update() time.sleep(0.03) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload