Python Forum
[pyGame] My First Test, Error Fount !
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[pyGame] My First Test, Error Fount !
#1
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.
Reply
#2
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()
Recommended Tutorials:
Reply
#3
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.
Reply
#4
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()
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Pygame attribute error djwilson0495 3 3,870 Feb-18-2021, 03:34 PM
Last Post: michael1789
Big Grin Error installing Pygame-Zero dpa2007 1 3,124 Dec-26-2020, 03:50 PM
Last Post: MK_CodingSpace
  pygame error in my clicker game CrazyMakes 2 2,489 Apr-19-2020, 03:04 AM
Last Post: Windspar
  Error to install pygame skp 1 3,445 Apr-14-2020, 05:17 PM
Last Post: joe_momma
  installing pygame error pylab 1 4,167 Dec-31-2019, 05:44 PM
Last Post: pylab
  [PyGame] pygame image loading error BlueClaw 6 6,291 Dec-10-2019, 08:50 PM
Last Post: BlueClaw
  Problem with music - Pygame.error GaseBall 1 3,135 Nov-28-2019, 07:46 PM
Last Post: SheeppOSU
  Pygame to exe error Clunk_Head 0 2,912 Oct-19-2019, 01:34 PM
Last Post: Clunk_Head
  [PyGame] Error setting up pygame wazee 10 13,143 Jun-14-2018, 11:19 PM
Last Post: wazee
  Pygame: Help With JackRouter Error arrangereality 4 4,981 Aug-02-2017, 03:28 AM
Last Post: arrangereality

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020