1

I am learning python and this is my first experience programming with GUI. I am designing a card game in which I created a game object and graphics(tkinter) object. I designed the GUI so that when user select cards and hit submit button, the tkinter will store the selected indices and set a flag in its member variables. At the same time, I want the game object to poll the flag, if the flag is set, the game object will get selected indices and proceed to rule checking, updating, etc.

I am using a while loop in that polling and I realized that the tkinter is also using a loop somewhere so that if I run with my current code, one of the loops will be blocked(either the GUI not shown or the game not proceeding).

I could only think of using multi-threads to let the game and graphics run concurrently. But is this too complicated? is there a way to do it in a single thread or any other methods?

Thanks!

martineau
  • 119,623
  • 25
  • 170
  • 301
  • This has been asked already, please see this answer: http://stackoverflow.com/a/1835036/7410808 – Lima Mairante Jan 12 '17 at 17:12
  • 2
    most games don't need threads but correctly constructed loop - and in `tkitner` you can use `after(miliseconds, function_name)` which can work like loop but it doesn't stop `mainloop()` – furas Jan 12 '17 at 17:16
  • 1
    @furas is right: Here's some [documentation](http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/universal.html) for the widget `after()` method. – martineau Jan 12 '17 at 17:18

0 Answers0