pygame

How to add text into a pygame rectangle

回眸只為那壹抹淺笑 提交于 2019-12-19 07:38:26
问题 I have come as far as drawing a rectangle in pygame however I need to be able to get text like "Hello" into that rectangle. How can I do this? (If you can explain it as well that would be much appreciated. Thank-you) Here is my code: import pygame import sys from pygame.locals import * white = (255,255,255) black = (0,0,0) class Pane(object): def __init__(self): pygame.init() pygame.display.set_caption('Box Test') self.screen = pygame.display.set_mode((600,400), 0, 32) self.screen.fill((white

pyGame within a pyGTK application

删除回忆录丶 提交于 2019-12-19 05:51:24
问题 What is the best way to use PyGame (SDL) within a PyGTK application? I'm searching for a method that allows me to have a drawing area in the GTK window and at the same time being able to manage both GTK and SDL events. 回答1: I've never attempted it myself, but hearing plenty about other people who've tried, it's not a road you want to go down. There is the alternative of putting the gui in pygame itself. There are plenty of gui toolkits built specifically for pygame that you could use. Most of

python pygame.camera.init() NO vidcapture

主宰稳场 提交于 2019-12-19 03:13:09
问题 I am trying to initialize the camera module in pygame and display video from a usb webcam. This is my code: import pygame import pygame.camera from pygame.camera import * from pygame.locals import * pygame.init() pygame.camera.init() cam = pygame.camera.Camera("/dev/video0",(640,480)) cam.start() image = cam.get_image() Yet i get this error: Traceback (most recent call last): File "C:/Users/Freddie/Desktop/CAMERA/Test1.py", line 7, in <module> pygame.camera.init() File "C:\Python27\lib\site

Installing Pygame on 64-bit Windows 7 and 64-bit Python 2.7

断了今生、忘了曾经 提交于 2019-12-19 02:21:08
问题 The title says it all. I do see similar questions, someone suggested about http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame, but all the pygame downloadable files are in .whl format which I have no idea how to run on Windows 7. I tried "cd [directory] > pip install [filename]" without success. 回答1: This worked from me (Windows 7, python 2.7, 64 bit): pip install C:/Users/ujjwal.karn/Downloads/pygame-1.9.2a0-cp27-none-win_amd64.whl I downloaded the file pygame-1.9.2a0-cp27-none-win_amd64.whl

Installing Pygame on 64-bit Windows 7 and 64-bit Python 2.7

落花浮王杯 提交于 2019-12-19 02:21:00
问题 The title says it all. I do see similar questions, someone suggested about http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame, but all the pygame downloadable files are in .whl format which I have no idea how to run on Windows 7. I tried "cd [directory] > pip install [filename]" without success. 回答1: This worked from me (Windows 7, python 2.7, 64 bit): pip install C:/Users/ujjwal.karn/Downloads/pygame-1.9.2a0-cp27-none-win_amd64.whl I downloaded the file pygame-1.9.2a0-cp27-none-win_amd64.whl

Fade Between Two Music Tracks in-progress in Pygame

折月煮酒 提交于 2019-12-18 13:33:19
问题 My intention is to have two music tracks , which are similar in nature, fade between each other at various times. When such a fade occurs, one music track should fade from full volume to muted in a short period of time, and, simultaneously, the other track should fade from 0 to 100 and continue playing from the same time index . They must be able to do this dynamically at any time - when a certain action occurs, the fade will occur and the new track will start playing at the same position

PyGame Custom Event

对着背影说爱祢 提交于 2019-12-18 13:26:39
问题 I want to ask about the use of custom events in pygame .. I experimented a little with pygame, so I know how usual pygame-generated events works .. My Question is , why would anyone be interested in a user event, does it help simplify combined pygame-events ? And how would someone implement it , and benefit from it in a real world example .. ? I found an example in a book I have been reading lately .. # creating the event CATONKEYBOARD = USEREVENT+1 my_event = pygame.event.Event(CATONKEYBOARD

Smooth Keyboard Movement in Pygame

Deadly 提交于 2019-12-18 12:36:38
问题 I'm using this code to have a player sprite move around a screen when the arrow keys are pressed: import pygame, sys, time from pygame.locals import * pygame.init() FPS=30 fpsClock=pygame.time.Clock() width=400 height=300 DISPLAYSURF=pygame.display.set_mode((width,height),0,32) pygame.display.set_caption('Animation') background=pygame.image.load('bg.png') UP='up' LEFT='left' RIGHT='right' DOWN='down' sprite=pygame.image.load('down.png') spritex=200 spritey=130 direction=DOWN pygame.mixer

Smooth Keyboard Movement in Pygame

心已入冬 提交于 2019-12-18 12:35:59
问题 I'm using this code to have a player sprite move around a screen when the arrow keys are pressed: import pygame, sys, time from pygame.locals import * pygame.init() FPS=30 fpsClock=pygame.time.Clock() width=400 height=300 DISPLAYSURF=pygame.display.set_mode((width,height),0,32) pygame.display.set_caption('Animation') background=pygame.image.load('bg.png') UP='up' LEFT='left' RIGHT='right' DOWN='down' sprite=pygame.image.load('down.png') spritex=200 spritey=130 direction=DOWN pygame.mixer

Pygame in Windows: ImportError: DLL load failed

孤街醉人 提交于 2019-12-18 12:32:35
问题 I just installed PyGame 1.9.1 (onto an existing python 2.6.4). Python and it standard libraries work, however, there is a problem with python even being able to find the pygame modules (correctly). Traceback (most recent call last): File "C:\foo\bar\firstGame.py", line 2, in <module> import pygame File "C:\python264\lib\site-packages\pygame\__init__.py", line 95, in <module> from pygame.base import * ImportError: DLL load failed: The specified module could not be found. Why is is this