Problem with pygame
holgertrampe (0)

Hi! I've got this error when i run an working pygame-script:
'bash -c polygott-x11-vnc q && DISPLAY=:0 run-project
nohup: redirecting stderr to stdout'
The code is perfectly working on local python-installation...need help! THX!

CODE
'
import pygame
pygame.init()

screenx = 400
screeny = 300
window = pygame.display.set_mode((screenx,screeny))

counter = 0

run = True

class Viereck:
x = 0
y = 0
breite = 0
hoehe = 0
farbe = (0,0,0)
speed = 10

def init(self, x, y, breite, hoehe, farbe):
self.x = x
self.y = y
self.breite = breite
self.hoehe = hoehe
self.farbe = farbe

def zeichneMich(self, fenster):
pygame.draw.rect(fenster, self.farbe, pygame.Rect(self.x,self.y,self.breite,self.hoehe))

def bewege(self, x, y):
self.x += x
self.y += y

viereck1 = Viereck(250,10,40,40,(255,255,255))
viereck2 = Viereck(10,150,20,20,(255,0,255))

def zeichne(fenster):
fenster.fill((0,0,0))
viereck1.zeichneMich(fenster)
viereck2.zeichneMich(fenster)
pygame.display.update()

while run:
pygame.time.delay(28)
zeichne(window)
counter +=1

VIERECKE BEWEGEN

#viereck1.bewege(counter1, 0)
#viereck2.bewege(counter
2, 0)
#if counter == 100:

run = False

for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False

keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
viereck1.bewege(viereck1.speed*-1, 0)

pygame.quit()
'

You are viewing a single comment. View All
heyitsmarcus (288)

In your repl code, I noticed that you have keys and the if statements following it wrapped in a set of ''' for some reason. If you remove those ''' from each line, it should run fine.

holgertrampe (0)

@heyitsmarcus Thx! But that is not the Problem...next time i will share my repl. When i copy the same code in a new repl, everything works as expected.

heyitsmarcus (288)

@holgertrampe It was the problem in the repl that I found in your profile that had this code. You only had the one repl at the time, and your keys section was outlined by three apostrophes. Something went wonky with copy and pasting on your end, but I'm glad it's working!