[Tutor] Tkinter mainloop()
ilcomputertrasparente at gmail.com
Tue Jul 6 15:59:13 CEST 2010
RTFM.... I happened to find the answer just a couple of hours after
having sent this message. How could I miss the update method of the Canvas?
Now my game works as expected, maybe I'll post it when it's complete.
Thanks to all!
Il 05/07/2010 21.00, Francesco Loffredo ha scritto:
> Hello all, this is the first time I ask for advice but I've been lurking
> for some month and i'm sure I'll find more than I need.
> I'm learning Python and Tkinter, and I chose an old board game as a
> practice field. I used a Canvas and many Polygons, one for each
> hexagonal space of the board, and I bound a mouse click to a PlacePiece
> function that handles the move. I managed to make it work for two human
> players, but when it came to let the computer play, I found a problem.
> I made a slightly different function, called Auto_PlacePiece, that
> doesn't get the target hex from an Event, but from arguments given, and
> I had to figure when this function has to be called. I thought an
> obvious place is at the end of the move, whether it's a manual or auto
> one. Just after having switched from a player to the other, if the new
> current player is "COMPUTER" then an automatic move is triggered.
> So, where's the problem? The problem is that the Canvas is refreshed,
> and the previous move becomes visible to the players, *only after the
> completion of the automatic move!* This is, I think, a consequence of
> the binding and a feature of Tk's mainloop(): the loop waits for the
> bound routine to end before redrawing the graphics, and unfortunately I
> call the automatic move inside (albeit at the very end) of the previous
> move. And now for the (long awaited) question:
> How can I ask a Canvas to redraw itself at my command? And if i can't,
> when should I call the auto move?
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> Nessun virus nel messaggio in arrivo.
> Controllato da AVG - www.avg.com
> Versione: 9.0.830 / Database dei virus: 271.1.1/2984 - Data di rilascio: 07/05/10 20:36:00
More information about the Tutor