[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Getting unknown error
- To: pygame-users@xxxxxxxx
- Subject: [pygame] Getting unknown error
- From: "Eric Hunter" <hunter.eric1@xxxxxxxxx>
- Date: Sun, 4 Nov 2007 17:11:28 -0500
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Sun, 04 Nov 2007 17:11:37 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; bh=BQB1PrnFpen6E8/6HGxKZP2/PlGz1ByVJ/TWeqJ6XZs=; b=LHVK6PcTDeXGxo54NN2wdnipf6lNrYmrFK2WA3cW2Fa4K95j3gqPbWg2IJAurFoNFCszJPsZLxxUh+gI/bm0ozQGLHXe3diigWoqbOZzRRlnxhkyxT9S2VT/yLeI7RbNAP2w+UVA0HtxtB6PzLc5mHO3zwRalLFUSm1fSOQTsUs=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type; b=UMhcFcZKteGTuZviVd1mQx8BvCxMEtRovrJlqE63aQF/0vMcaOp9VYNgdcWtrZerIBoeNiR1FQE3V6bm6hyCgeGenigmaqpOrMWulG1wfxk3OrbJiDLgpY5/2ipBql3kAw/fg/uF19Rpj2aDgAzf8CVbTLIahgBhzAIqj2uHySo=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
I've never heard of this error before: UnboundLocalError: local variable 'rect' referenced before assignment
[code]
import os, sys
import pygame
from pygame.locals import *
import pickle
rect = {}
class LockandStock():
def __init__(self):
pygame.init()
self.window = pygame.display.set_mode((640, 480))
self.surface = pygame.Surface(self.window.get_size
())
self.surface.convert()
#self.pictureglass = pygame.Surface((640, 480))
#self.pictureglass.convert()
self.surface.fill((255, 255, 255))
#self.pictureglass.fill((255, 255, 255))
def MainLoop(self):
while True:
for self.event in pygame.event.get():
if self.event.type == QUIT:
return
elif self.event.type
== pygame.KEYDOWN:
if self.event.key == K_n:
self.surface.fill((118, 118, 118))
elif self.event.key == K_o:
try:
self.image_name = raw_input("Name of Pciture: ")
self.image = pygame.image.load(self.image_name)
self.image = self.image.convert()
self.surface.blit(self.image, (0, 0))
self.last = self.image_name[(len(self.image_name) - 4): len(image_name)]
except:
print "*** Picture not found! ***"
elif self.event.key == K_i:
try:
self.in_file = open((self.image_name.strip(self.last)) + ".las", "r")
rect =
pickle.load(self.in_file)
self.in_file.close()
for x in rect.keys():
pygame.draw.rect(self.surface, ((255, 255, 0)), rect[x], 1)
self.numRect = x
except:
print "*** No .las file to load! ***"
elif self.event.type == pygame.MOUSEBUTTONDOWN
:
if self.event.button == 1:
# If point_draw = 1, get x,y of mouse
if self.point_draw == 1:
self.mouseX1, self.mouseY1 = pygame.mouse.get_pos
()
self.point_draw = 2
else:
# If point_draw = 2, get x,y of mouse, make a rect and throw it in a dictionary
self.mouseX2, self.mouseY2 =
pygame.mouse.get_pos()
self.numRect += 1
self.newRect = pygame.Rect(self.mouseX1, self.mouseY1, self.mouseX2 - self.mouseX1, self.mouseY2 - self.mouseY1)
rect[self.numRect
] = self.newRect
self.point_draw = 1
elif self.event.button == 3:
self.mouseXTEMP, self.mouseYTEMP = pygame.mouse.get_pos()
for x in rect.keys():
if rect[x].collidepoint(
self.mouseXTEMP, self.mouseYTEMP):
del rect[x]
self.numRect -= 1
# draws the rectangles in the rect{}
if rect.keys() <> 0:
for i in
rect.keys():
pygame.draw.rect(self.surface, ((255, 255, 0)), rect[i], 1)
self.window.blit(self.surface, (0, 0))
pygame.display.flip()
if __name__ == "__main__":
app = LockandStock()
app.MainLoop()
[/code]
any help is great. thanks in advance.
-Eric