#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    3
    Rep Power
    0

    problems with tkinter, are while loops possible?


    im making a very simple game where right now the controllable character is a rectangle on a canvas. i bound function for the movement to the arrow keys, and the rectangle is moved by canvas.move()

    my problem is that i want the arrow keys to simple change the direction of the movement and have the rectangle always move in that direction without key presses. so i tried a while loop which seemed like the natural solution, but the problem is the entire loop has to be executed before the window is created and while 1: loops make it freeze. is there any solution to this?
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    while loops are possable in GUI's , that i do know! I guess what you should be doing is calling your 'move this way' function inside your while loop.. if you have some code i'll take a look

    Oh, in Python 2.3+ you should use the True keyword instead of 1 (as long as you arnt bothered about back compatability), so your while loop should look like this..

    while True:
    ...
    do whatever
    ...

    Also, if you want to make games with Python can i suggest you try Pygame, its allot more powerful and this is what it was built for!

    http://www.pygame.org/

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    3
    Rep Power
    0
    i know of pygame, i learned a bit and to be honest i dont like it a lot. for this simple game i know i can avoid it. heres thing the thing, there is no while loop. in tkinter, the only way i know of making things work is in events, and i tried puting a while loop in an event but again its as if the loop finishes in one go and and then everything is displayed, its in explicable. does anyone ahve any experience with this?

IMN logo majestic logo threadwatch logo seochat tools logo