pygame

Loop over a list containing path to sound files [duplicate]

会有一股神秘感。 提交于 2021-01-29 21:10:29
问题 This question already has answers here : How do I schedule an audio file to play automatically in pygame after the first song ends? (1 answer) Pygame Playlist without while True loop (1 answer) Pygame Music Queue not functioning [closed] (2 answers) Closed 5 months ago . So what I was planning to do was loop over a list which contains path to my sound files and play them using pygame.mixer module in python, but when I did this the problem I encountered was pygame always play the last most

Why is my PyGame application not running at all?

橙三吉。 提交于 2021-01-29 21:08:18
问题 I have a simple Pygame program: #!/usr/bin/env python import pygame from pygame.locals import * pygame.init() win = pygame.display.set_mode((400,400)) pygame.display.set_caption("My first game") But every time I try to run it, I get this: pygame 2.0.0 (SDL 2.0.12, python 3.8.3) Hello from the pygame community. https://www.pygame.org/contribute.html And then nothing happens. Why I can't run this program? 回答1: Your application works well. However, you haven't implemented an application loop: #!

Why is nothing drawn in PyGame at all?

淺唱寂寞╮ 提交于 2021-01-29 21:05:43
问题 i have started a new project in python using pygame and for the background i want the bottom half filled with gray and the top black. i have used rect drawing in projects before but for some reason it seems to be broken? i don't know what i am doing wrong. the weirdest thing is that the result is different every time i run the program. sometimes there is only a black screen and sometimes a gray rectangle covers part of the screen, but never half of the screen. import pygame, sys from pygame

How do I detect if the mouse is hovering over a button? PyGame button class is not displaying the text or changing colour on hover

风格不统一 提交于 2021-01-29 21:05:10
问题 I have created a button class in pygame and although the button itself is displaying, my text is not showing up. Also I have some conditions to change the colour when the mouse is over the button. I have achieved the desired result using hard coded values in my main function, however I want to use a class the handle my various button as I might have quite a few buttons. Given below are some classes that I'm using Fonts class Fonts: def __init__(self, font, antialias, text, color, x, y): self

Pygame already installed; however, python terminal says “No module named 'pygame' ” (Ubuntu 20.04.1)

故事扮演 提交于 2021-01-29 21:04:46
问题 I'm using Ubuntu 20.04.1 LTS. I have installed pygame with sudo apt-get install python-pygame . However, when I run my code using VS code, the python terminal gives the output below: Traceback (most recent call last): File "path", line 1, in <module> import pygame ModuleNotFoundError: No module named 'pygame' I tried to reinstall Pygame using the same command. Here is the output: Reading package lists... Done Building dependency tree Reading state information... Done python-pygame is already

Pygame doesn't let me use float for rect.move, but I need it

若如初见. 提交于 2021-01-29 21:03:12
问题 I've recently recreated a version of Lunar Lander (you know, the old retro game) in Python 3 and Pygame: my lander moves (̀̀̀ rect.move ) each frame along the y axis because of gravity.\ Problem: Until I hit 1 m/s, the y value added to rect.move is a float under 1: I must use int() to round it up, as pygame doesn't like floats. In a previous version with Tkinter, the y coord of the lander was like this: 0.01 0.02 ... 0.765 1.03 1.45 ... In pygame it's 0 0 0 ... 1 1 1 2 2 ... This is really

Utilising the pygame.mixer.music.get_endevent()

落花浮王杯 提交于 2021-01-29 19:39:56
问题 I want a tkinter label to show nothing when a sound effect has finished. I've been researching the www on how to create/initialise/catch the end of music event with no luck. def play_btn(): if mixer.music.get_busy(): mixer.music.fadeout(1000) snd_fyl.set(snd_list.get(ACTIVE)) mixer.music.load(snd_dir+"/"+snd_list.get(ACTIVE)+"mp3") mixer.music.play() def stop_btn(): mixer.music.stop() clear_label() def clear_label(): snd_fyl.set("") snd_lbl1 = LabelFrame(MainWindow, text="Sound effect playing

Why is my PyGame application not running at all?

百般思念 提交于 2021-01-29 18:31:18
问题 I have a simple Pygame program: #!/usr/bin/env python import pygame from pygame.locals import * pygame.init() win = pygame.display.set_mode((400,400)) pygame.display.set_caption("My first game") But every time I try to run it, I get this: pygame 2.0.0 (SDL 2.0.12, python 3.8.3) Hello from the pygame community. https://www.pygame.org/contribute.html And then nothing happens. Why I can't run this program? 回答1: Your application works well. However, you haven't implemented an application loop: #!

How to make an executable with Python and Pygame

喜你入骨 提交于 2021-01-29 16:06:56
问题 I need some help with making an executable out of a Python script. I have tried cx_freeze but get No module named re and I cant use py2exe because I am using Python 3.3.2. The code of my setup.py file for cx_freeze : import sys from cx_Freeze import setup, Executable setup( name = "10SecondDestruction" , version = "1.0" , description = "10SecondDestruction" , executables = [Executable("10 Second Destruction.py")] , ) 来源: https://stackoverflow.com/questions/19192091/how-to-make-an-executable

drawing objects on pygame

隐身守侯 提交于 2021-01-29 14:30:45
问题 I am restarting some code for a covid simulation as I cant use the collide function in my current one. I have been able to draw the basic background, and draw one cell. However, when i try create the cell in a different place on my screen it does not appear for some reason. My code is as seen below: import random import pygame # import numpy import time pygame.init() GREEN1 = (0, 255, 0) # Healthy cells RED = (255, 0, 0) # Infected cells GREEN2 = (0, 100, 0) # Healthy cells not susecptible