So there I was just messing around in an interpreter when I came across a strange problem. I was just trying to make a bouncing smiley face to brighten my day, but for some reason I’m unable to do this. And I have no desire to do this in Pygame, if anyone thinks to suggest that. This isn’t a project, it was just something silly I was doing and don’t understand why it’s not working.
from Tkinter import *
import time,random
root = Tk()
root.geometry("500x500")
root.mainloop()
bouncer = Label(root, text="=D")
def bounce ():
X = random.randint(1,500)
Y = random.randint(1,500)
bouncer.place(x=X, y=Y)
while True:
time.sleep(0.5)
bounce()
This code does not work, and I for the life of me can’t figure out why. What ends up happening is the loop runs forever, and when I ^C bounce() gets called once and the script ends. I tried it in a for loop to see if I could just bounce 100 times, but bounce() would just call once after the loop finished. I’m fairly stumped on this.
Any ideas, anyone?
sleepputs the process to the sleep state. Better useafter.