I'm trying to get my raiselines() and then redraw() to loop. I've tried putting the loop command in different spots and using different methods. While stop==false, x in range(500), etc. Why can I only get this to draw the original lines but not get them to raise up?
If anyone can spot the error I'm missing here that would be much appreciated.
import random
from Tkinter import *
def main():
#first run, get all new lines
numberoflines = 8
for x in range (numberoflines):
addline()
liney[x] = (wh/numberoflines) * x
linecolor[x] = "black" #can change later
print "x=", x," ",0,liney[x],hole1[x],liney[x]+lineh
print hole2[x],liney[x],wright,liney[x]+lineh
redraw()
for repeat in range(500):
raiselines()
print "RAISING!"
def addline():
for x in range(100):
if x not in liney: #find next unused number in dic
print "next number =", x
break
hole1[x] = random.randrange(0,ww-holesize) #make left x of hole
hole2[x] = hole1[x]+holesize #find right x, change hole x values to tuple
print hole1[x],hole2[x]
liney[x] = wbottom - lineh #start new line at bottom
def raiselines():
deleteline = 99
linesmoved = 0
for x in range(100):
if x in liney:
liney[x]-=linespd
linesmoved +=1
#if linesmoved == numberoflines + 1:
# break
if liney[x] + lineh -linespd < 0: #kill line, bottom of line is offscreen
deleteline = x
if deleteline != 99: #if a line is off the screen completely, kill it
del liney[x]
redraw() #once the new liney values are found, redraw everything
def redraw():
window.delete(ALL) # This erases everything on the canvas.
for x in liney:
if liney[x]<0:liney[x]=0 #incase anything is off screen
window.create_rectangle(0,liney[x],hole1[x],liney[x]+lineh, fill=linecolor[x]) #line before hole
window.create_rectangle(hole2[x],liney[x],wright,liney[x]+lineh, fill=linecolor[x]) #line after ho
window.update() # This refreshes the drawing on the canvas.
window.after(cycle_period) # This makes execution pause for some milliseconds.
root.mainloop()
ballmins = 15 #min speed of ball from 0
ballmaxs = 20 #max speed of ball (if I decide to accelerate the ball)
ballacc = 1.3 #may or may not accelerate ball. 1 = no accel, >1 = accel
lineh = 14 #thickness of lines (height of box)
linespd = 10 #how fast to raise lines
wh = 700 #window height
ww = 600 #window width
wleft = 0
wtop = 0
wright = wleft + ww #a lot of these seem useless, but i think they will
wbottom = wtop + wh #make everything easier to understand in the code
holesize = 80
ballsize = 75
# i <3 dics
liney = {}
linecolor = {}
hole1 = {}
hole2 = {}
#gui
root = Tk()
root.title("Fall Down")
cw = 1000 # canvas width
ch = 1000 # canvas height
window = Canvas(root, width=cw, height=ch, background="white")
window.grid(row=0, column=0)
cycle_period = 1 # time between frames in ms
if __name__ == '__main__':
main()

New Topic/Question
Reply



MultiQuote



|