|
| Débuté par wanmobi01, 20 fév. 2023 16:17 - 2 réponses |
| |
| | | |
|
| |
| Posté le 20 février 2023 - 16:17 |
Python 3.3.2 and pygame-1.9.2a0.win32-py3.3.msi were just downloaded. I've decided to attempt a couple YouTube lessons and see whether they work.
I tried 'Game Development Tutorial - 2 - Basic Pygame Program' by thenewboston to see whether it worked. It is designed to generate a dark background and a mouse-shaped ball (or so I think). When I try to execute it, I get a syntax error; if I delete it, all I get is a dark pygame window. The code is as follows:
bgg="bg.jpg" ball="ball.png"
import pygame, sys from pygame.locals import *
pygame.init() screen=pygame.display.set_mode((540,341),0,32)
Background=pygame.image.load(bgg).convert() mouse_c=pygame.image.load(ball).convert_alpha()
WHILE True: for Event IN pygame.event.get(): IF Event.type ==QUIT: pygame.quit() sys.exit()
screen.blit(Background), (0,0))
The display. The blit(bakcgorund, (0,0)) command is the issue; when it encounters a syntax mistake, it emphasises the second bracket on the command's far right. This https://www.scaler.com/topics/python/ has taught me When I delete it, all that remains is a black pygame window. Can somebody assist me? |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 30 messages |
|
| Posté le 20 février 2023 - 23:32 |
| Try removing the bracket after the word background in that line |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 5 messages |
|
| Posté le 23 février 2023 - 10:34 |
There are a few syntax errors in your code that need to be fixed. Here's the corrected code:
scss Copy code import pygame import sys from pygame.locals import *
pygame.init() screen = pygame.display.set_mode((540, 341), 0, 32)
bgg = "bg.jpg" ball = "ball.png"
background = pygame.image.load(bgg).convert() mouse_c = pygame.image.load(ball).convert_alpha()
while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit()
screen.blit(background, (0, 0)) pygame.display.update() Here are the changes I made:
Capitalized the W in while Changed WHILE to while Lowercased the E in Event Changed IN to in Capitalized QUIT Renamed Background to background Moved screen.blit and pygame.display.update inside the while loop With these changes, the code should display the background image and a black mouse-shaped ball on top of it.
https://www.partycityfeedback.net/ |
| |
| |
| | | |
|
| | | | |
| | |
|