Ich habe mir kürzlich eine MacBook Pro gekauft, und wollte meine Python-programme übertragen.
Auf Windows hat das ganze noch Funktioniert, jetzt bekomme ich einen Fehler bei "def renntest((" 2. klammer. (Python und pygame sind installiert)
Code: Alles auswählen
import pygame, sys, random
pygame.init()
screen = pygame.display.set_mode([700, 600])
pygame.display.set_caption("wolfram")
def rentext((x,y),text,size): #renders text
font = pygame.font.Font("tahoma.ttf", size)
text = font.render(text, 1, [0,0,0])
screen.blit(text, [x, y])
class button:
def __init__(self, (x,y), text):
self.x = x
self.y = y
self.text = text
self.render()
def render(self):
if self.mouseover():
pygame.draw.rect(screen,[125, 95, 35],(self.x , self.y , 50, 20))
else:
pygame.draw.rect(screen,[ 0, 0, 0],(self.x , self.y , 50, 20))
pygame.draw.rect(screen, [220,220,220],(self.x+1, self.y+1, 48, 18))
rentext((self.x+2, self.y+3), self.text, 9)
def mouseover(self):
if pygame.mouse.get_pos()[0]>=self.x and pygame.mouse.get_pos()[0]<=self.x+50:
if pygame.mouse.get_pos()[1]>=self.y and pygame.mouse.get_pos()[1]<=self.y+20:
return True
else:
return False
def test(self):
return self.mouseover()
class switch:
def __init__(self, (x, y), state, text):
self.x = x
self.y = y
self.state = state
self.text = text
self.render()
def render(self):
pygame.draw.rect(screen,[220,220,220],(self.x ,self.y-1,11,11))
if self.mouseover():
pygame.draw.rect(screen,[125, 95, 35],(self.x ,self.y ,10,10))
else:
pygame.draw.rect(screen,[0 , 0, 0],(self.x ,self.y ,10,10)) #rect
pygame.draw.rect(screen,[255,255,255],(self.x+1,self.y+1, 8, 8))
rentext((self.x+15, self.y-1), self.text, 9)
if self.state:
pygame.draw.lines(screen,[0,0,0],0,([self.x+2,self.y+4],[self.x+5,self.y+7],[self.x+11,self.y-3]))
pygame.draw.lines(screen,[0,0,0],0,([self.x+2,self.y+3],[self.x+5,self.y+6],[self.x+11,self.y-4]))
def mouseover(self):
if pygame.mouse.get_pos()[0]>=self.x and pygame.mouse.get_pos()[0]<=self.x+10:
if pygame.mouse.get_pos()[1]>=self.y and pygame.mouse.get_pos()[1]<=self.y+10:
return True
else:
return False
def test(self):
if self.mouseover():
self.state = not self.state
return True
else:
return False
def rhs(): #creates menu
pygame.draw.rect(screen, [192,192,192], (600, 0, 100, 600))
pygame.draw.rect(screen, [220,220,220], (600, 0, 2 , 600))
rentext((605, 2),"Options",20)
s1.render()
s2.render()
s3.render()
b1.render()
def next():
global x
global pixo
global pix
s = pixo[cc(x-2)]+pixo[cc(x-1)]+pixo[cc(x)]+pixo[cc(x+1)]+pixo[cc(x+2)]
if s == 2 or s == 4:
p = 1
color = (0,0,0)
else:
p = 0
color = (255,255,255)
screen.set_at((x*pxo,y*pxo),color)
x += 1
return p
def newline():
pixo = pix
x = 0
global y
y += 1
def crenew():
pix = []
pso = pixsize
for i in range(0, 600/pixsize):
r = random.randint(0,1)
pix.append(r)
if r:
color = (0,0,0)
else:
color = (255,255,255)
screen.set_at((len(pix)-1,0),color)
def cc(number):
if number < 0:
return len(pix) + number
elif number > len(pix):
return number-len(pix)
else:
return number
pix = []
pixo = []
pixsize = 1
pxo = 1
x = 0
y = 1
b1 = button((610, 40), "Create new")
s1 = switch((610, 80), True, "1")
s2 = switch((610, 100), False, "2")
s3 = switch((610, 120), False, "4")
crenew()
print pix
pixo = pix
while True:
if x>600:
newline()
pix.append(next())
rhs()
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
if s1.test():
s2.state = False
s3.state = False
pixsize = 1
if s2.test():
s1.state = False
s3.state = False
pixsize = 2
if s3.test():
s1.state = False
s2.state = False
pixsize = 4
if b1.test():
crenew()
(bitte kritisiert nicht meinen Programmierstil, ich wuesste einfach gerne, wo der Fehler liegt)
Danke,
Kamik423