Hi, I have two similar programs- one in Livewires and one in Tkinter. Just moving the player on a canvas. Why is that one in Tkinter so slow? What did I miss? Livewires is based on Tkinter, so it should be the same. I looked at the code of Livewires, tried something, but no success. Maybe its because of sleeping part in event handler in Tkinter, that is somehow (how?) bypassed in Livewires by magic tkinter.dooneevent(tkinter.DONT_WAIT). Neither this worked with me. Could anyone help? Both programs attached. livewires: http://www.livewires.org.uk/python/lwpackage.html -- geon Pavel Kosina |
from livewires import * from random import randint def makePlayer(): global player_body, player_x, player_y player_x=randint(0,640) player_y=randint(0,480) player_body=circle(player_x, player_y,5, filled=1) def movePlayer(): global finito, player_body, player_x, player_y keys=keys_pressed() if '2' in keys: player_y=player_y-krok if '4' in keys: player_x=player_x-krok if '6' in keys: player_x=player_x+krok if '8' in keys: player_y=player_y+krok if 'q' in keys: finito=1 move_to(player_body, player_x, player_y) begin_graphics() allow_moveables() makePlayer() finito=0 krok=0.1 while not finito: movePlayer() end_graphics()
from Tkinter import * import random def makeCanvas(): global canvas, root root=Tk() canvas=Canvas(root, width=640, height=480, bg="white") canvas.pack() def makePlayer(): global player x1,y1=random.randint(0,640), random.randint(0,480) x2,y2=x1+10, y1+10 player=canvas.create_oval(x1,y1,x2,y2, fill="blue") root.bind("<Key>", movePlayer) def movePlayer(event): if event.char=="8": # nahoru dx,dy= 0,-step elif event.char=="6": # vpravo dx,dy= step, 0 elif event.char=="2": # dolu dx,dy= 0, step elif event.char=="4": # vlevo dx,dy= -step,0 else: return canvas.move(player, dx, dy) # ----------- root program -------------------------------- step=1 makeCanvas() makePlayer() mainloop()
-- http://mail.python.org/mailman/listinfo/python-list