python - Why is Pygame's KMOD_SHIFT unresolved and crashing my code? -
i wrote simple program test detection of shift key being pressed, think ought work. main issue seems kmod_shift piece. searched out shift detection using pygame , test pygame.key.get_mods() & kmod_shift
people said use, , in several code example well. however, in code warning kmod_shift unresolved reference, , when try run code, press key error: "name kmod_shift undefined".
isn't pygame supposed define it? in other people's code examples of using this, seem using same me. doing wrong here?
still major python newbie - guidance.
#! /usr/bin/python3 import pygame pygame.init() screen_width, screen_height = 800, 600 screen_color = [128, 128, 128] game_display = pygame.display.set_mode((screen_width, screen_height)) pygame.display.set_caption('coloriffic') clock = pygame.time.clock() my_font = pygame.font.sysfont("monospace", 45) crashed = false shift_label = my_font.render("shift not pressed", 1, (0, 0, 0)) while not crashed: event in pygame.event.get(): if event.type == pygame.quit: crashed = true if event.type == pygame.keydown: if pygame.key.get_mods() & kmod_shift: # problem line shift_label = my_font.render("shift pressed", 1, (0, 0, 0)) else: shift_label = my_font.render("shift not pressed", 1, (0, 0, 0)) game_display.fill(screen_color) game_display.blit(shift_label, (100, 100)) pygame.display.update() clock.tick(60) pygame.quit() quit()
nevermind, seems if use pygame.kmod_shift
works fine. don't know why other people didn't have put "pygame." in front, maybe imported pygame differently did.
false alarm, apologies.
Comments
Post a Comment