Python Forum
[pyGame] My First Test, Error Fount ! - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Game Development (https://python-forum.io/forum-11.html)
+--- Thread: [pyGame] My First Test, Error Fount ! (/thread-5237.html)



[pyGame] My First Test, Error Fount ! - JamieVanCadsand - Sep-24-2017

Hey Programmers...

I try to set up an screen with pygame, but i get an error. I want to learn pyGame and pyOpenGL
to write my own software, but this is an test to settup an screen...

My Script:
import pygame

# Set the Screen:
pygame.init()
screen = pygame.display.set_mode(640, 480)
screen.fill(0, 0, 0)
pygame.display.flip()

# Quit Program:
pygame.event.pump()
if(pygame.key.get_pressed(K_ESCAPE)):
    quit()
The Error:
Error:
Traceback (most recent call last): File "C:\Users\Gebruiker\Desktop\GameTest.py", line 5, in <module> screen = pygame.display.set_mode(640, 480) TypeError: argument 1 must be 2-item sequence, not int
What do i bad ?... Can anyone help me about how i can create an screen in pyGame ?...
I find it more difficult...

Can anyone help me, only for setup an screen ?... I want to learn it... i get pyGame
installed from PIP, Windows 7. I use python 3.6.2... This is an little test with pyGame.

Thanks for help, Jamie.


RE: [pyGame] My First Test, Error Fount ! - metulburr - Sep-24-2017

It needs to be a sequence such as a tuple is what most people use
screen = pygame.display.set_mode((640, 480))
https://www.pygame.org/docs/ref/display.html#pygame.display.set_mode

Also make sure you add a clause to close for the little X on the windows via pygame.QUIT. And its better to loop events and close on such events, as well as put your screen fill and screen updates in the main game loop to update. An example below...

import pygame

screen = pygame.display.set_mode((800,600))
done = False

while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                done = True
        
    screen.fill((255,255,255))
    pygame.display.update()



RE: [pyGame] My First Test, Error Fount ! - JamieVanCadsand - Sep-25-2017

OK, i get tryed this code, but pygame don't close the screen if i press "Escape"...
Now is the question whats wrong... i get problems with pyGame if i use this script.

Can anyone help me how i can use events to quit this screen ?...
Thanks for help, Jamie.


RE: [pyGame] My First Test, Error Fount ! - metulburr - Sep-25-2017

It closes on the x but not the escape key? Did you copy my code or did you type it in. Check for typos. Are you using an IDE? If so which IDE?

I think there were some issues with IDLE in which require sys.exit and pygame.quit such as
import pygame
import sys
 
screen = pygame.display.set_mode((800,600))
done = False
 
while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                done = True
         
    screen.fill((255,255,255))
    pygame.display.update()
pygame.quit()
sys.exit()