Im trying out object orientated coding, and so im sure my code isnt optimal, but I dont mind at the moment.
My problem is I cant seem to get the random number function to seed. It doesnt throw up any errors, but I consistently get the same random numbers.
from Tkinter import*
from Canvas import*
from random import*
class main(Frame):
def __init__(self,master=None):
Frame.__init__(self,master)
self.config(bg="dark slate blue")
self.grid()
self.box=Canvas(self,bg="burlywood4")
self.box.grid()
class grass():
health=100
energy=5
age=0
xpos=randint(0,200)
ypos=randint(0,200)
def __init__(self):
pass
def growth(self):
if grass.health>80:
line=Canvas.create_line(main.box,self.xpos,self.ypos,self.xpos,self.ypos+10,fill="green")
print self.xpos,self.ypos
print grass.health
main=main()
grass1=grass()
seed()
grass2=grass()
seed()
grass3=grass()
grass1.growth()
grass2.growth()
grass3.growth()
main.mainloop()


Sign In
Create Account


Back to top









