#πŸ”’ pygamee open screen not working

107 messages Β· Page 1 of 1 (latest)

runic thunderBOT
#

@iron vortex

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

iron vortex
#

it said pygame.init() is wrong idk why

final harbor
#

if Python is outputting an error message when you try to run your program it would be useful if you also posted that so we can help to diagnose your problem

iron vortex
#

no it s not saying error

#

its just flashing a screen for 1 second

final harbor
#

alright

iron vortex
fluid sorrel
#

you have some funny spaces before some lines

#

lines 2,3,6

final harbor
#

ah you are getting an error

iron vortex
#

how i fix

fluid sorrel
#

also i think the pygame init call has to come last, but i'm not really sure

final harbor
# iron vortex

when you write Python code, you have to have consistent whitespace so Python knows what scope the code belongs to

#

I think there's a command which explains this

#

!indentation

#

ah, well

iron vortex
#

can u dumb it down im a noob to python

#

idk what that means

final harbor
#

Okay so indentation refers to the whitespace (which basically just means spaces/tabs/or any other character which represents a 'space') that you put before each line. In your code you have a space before pygame.init() so the Python interpreter sees pygame.init() (note the leading space). In some languages indentation is not important but in Python you have to be careful how you indent because the interpreter uses it to determine how statements are grouped together. I can illustrate what 'grouped together' means by this example ```py
my_variable = 'hello'
another_variable = input('type a word: ') # prompt the user to input a word

if my_variable == another_variable:
# only the code we have 'indented' will be ran if the above statement is true
print('you said hello!'
else:
print('you said something else')

iron vortex
#

...

final harbor
#

To fix your problem, you will have to remove the leading spaces on lines 3 and 5 (your linter has highlighted them in red for you)

iron vortex
#

5 has no space

#

u mean 6

#

i deleted all

#

ok

#

ama try now

final harbor
iron vortex
#

it still did that

#

join voice chat 0

teal swan
#

i remember pygame

iron vortex
#

ama share screen

teal swan
#

i quit it

#

its long

iron vortex
#

oh ok

teal swan
#

u rather do unity or smthn

final harbor
iron vortex
#

naw id code

teal swan
#

in unity

iron vortex
#

i cant

#

how bowt 4

teal swan
#

4?

iron vortex
#

im talking to cat

teal swan
#

how

#

oh

iron vortex
#

im trrying to show error

#

no 1

final harbor
#

if you could send a screenshot that would probably be fine too

teal swan
#

i remember i memorised the default beginning for starting a basic window

iron vortex
#

no it hapen in the blink of a eye

final harbor
#

I think you have to get voice verified to be able to stream

iron vortex
#

as soon as i open it it closes

teal swan
iron vortex
#

i did that

final harbor
iron vortex
#

oh ill try

#

it said screen = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT = 600))

final harbor
#

when you're debugging, you have to look at the error message that the programming language is reporting to you, not just the offended line

teal swan
#

pygame.init()
screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption("Basic Window")

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

pygame.quit()
#

try

iron vortex
#

it said

#

import pygame
ModuleNotFoundError: No module named 'pygame

#

dude this just wont work

#

idk why

teal swan
#

well u didnt install it then

iron vortex
#

wdy mean

teal swan
#

pip instally pygame

#

did u do that

iron vortex
#

where do i put that in

teal swan
#

terminal

#

vs code?

iron vortex
#

A new release of pip is available: 24.0 -> 24.3.1
[notice] To update, run:

teal swan
#

dont matter

#

now try

iron vortex
#

ok

#

YAY IT WORKED

#

:)

#

TY

teal swan
#

🫑

iron vortex
#

w

teal swan
#

well ill tell u pygame does get very confusing pnce u get deep into the stuff

#

like those big games

iron vortex
#

mm where can i learn pygame code

teal swan
#

yt?

final harbor
#

if you're unfamiliar with some of the basics of how Python works then it may be worth reading some of the sections of the 'Automate the Boring Stuff' book (which you can read online for free) before attempting to continue with pygame. Specifically relating to your issue is this section on Control Flow and indentation (the book says 'Blocks')

#

it will be easier for you to write code with pygame if you understand the basics first

#

!res
There are some other resources here as well

runic thunderBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

teal swan
iron vortex
#

oh ill try

teal swan
#

i wanna do machine learning so ye

#

machine learning looks cool

final harbor
#

definitely! It's also something that Python is used a lot for

iron vortex
#

ummmmmmm yea no idk what this is

teal swan
#

theres so much

iron vortex
#

i watch tutorials

teal swan
#

same

#

i wanna build smthn very cool

quaint oriole
#

I usually recommend Clear Code on youtube, there are a few others too, Tech with Tim, Programming with Nick, DaFluffyPotato, but recommend being decent at python too, pygame is not really a python beginner thing

teal swan
#

and for exams

#

it involves basic physics sorta

#

like velocity

#

and vectors

runic thunderBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.