event GETPRESSED
cardflip rapid flipper.py
import pygame pygame.init() from cardimg import img #create a list of pre-loaded card images: card_images = [] for data in img: card_images.append(pygame.image.load(img[data])) screen = pygame.display.set_mode((640, 480)) import random current_image = card_images[random.randint(1,52)] done = False while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True #KEYDOWN - single press: elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: done = True elif event.key == pygame.K_SPACE: current_image = card_images[random.randint(1,52)] # key.get_pressed() >> polls current state of every key on the # keyboard, note this sits outside the FOR event.get() loop: keys = pygame.key.get_pressed() if keys[pygame.K_RETURN]: #ENTER KEY - held down: current_image = card_images[random.randint(1,52)] screen.blit(current_image, (233, 200)) pygame.display.flip() pygame.quit()
cardimg.py
# ----------------------------------------------------------- # loads a deck of online card images into a local dictionary # # (C) 2020 digisoln.com # Released under GNU Public License (GPL) # ----------------------------------------------------------- img = {} import io, requests img["cardback"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/cardback.gif").content) img["2c"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/2c.gif").content) img["2d"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/2d.gif").content) img["2h"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/2h.gif").content) img["2s"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/2s.gif").content) img["3c"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/3c.gif").content) img["3d"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/3d.gif").content) img["3h"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/3h.gif").content) img["3s"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/3s.gif").content) img["4c"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/4c.gif").content) img["4d"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/4d.gif").content) img["4h"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/4h.gif").content) img["4s"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/4s.gif").content) img["5c"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/5c.gif").content) img["5d"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/5d.gif").content) img["5h"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/5h.gif").content) img["5s"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/5s.gif").content) img["6c"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/6c.gif").content) img["6d"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/6d.gif").content) img["6h"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/6h.gif").content) img["6s"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/6s.gif").content) img["7c"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/7c.gif").content) img["7d"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/7d.gif").content) img["7h"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/7h.gif").content) img["7s"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/7s.gif").content) img["8c"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/8c.gif").content) img["8d"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/8d.gif").content) img["8h"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/8h.gif").content) img["8s"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/8s.gif").content) img["9c"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/9c.gif").content) img["9d"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/9d.gif").content) img["9h"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/9h.gif").content) img["9s"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/9s.gif").content) img["tc"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/tc.gif").content) img["td"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/td.gif").content) img["th"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/th.gif").content) img["ts"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/ts.gif").content) img["jc"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/jc.gif").content) img["jd"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/jd.gif").content) img["jh"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/jh.gif").content) img["js"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/js.gif").content) img["qc"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/qc.gif").content) img["qd"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/qd.gif").content) img["qh"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/qh.gif").content) img["qs"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/qs.gif").content) img["kc"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/kc.gif").content) img["kd"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/kd.gif").content) img["kh"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/kh.gif").content) img["ks"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/ks.gif").content) img["ac"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/ac.gif").content) img["ad"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/ad.gif").content) img["ah"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/ah.gif").content) img["as"] = io.BytesIO(requests.get("https://digisoln.com/resources/cards/as.gif").content)