Solved

How to Integrate PyGame with TK?

Posted on 2011-03-08
2
461 Views
Last Modified: 2012-05-11
I have a small program that I'm trying to integrate a Tk Form with PyGame.  I am able to draw a pygame screen and a Tk form, but the two don't work well together. I am having a couple of problems.    This is attached as a simple example to draw a circle at X,Y with a specific radius.  

1.  No Screen Refresh - When I drag the Tk form over the game field, it erases the game field.  How can I fix this?  My gut says this is a threading problem, but I don't know how to deal with it.

2.  How does the form see the pygame elements in order to plot the circle where I want it?

Any expert advice on how to elegantly integrate Tk with pygame is appreciated.
ee-1.py
0
Comment
Question by:tmonteit
2 Comments
 
LVL 16

Accepted Solution

by:
gelonida earned 500 total points
ID: 35080315
I know neither pygame nor pytk.

But perhaps my comment can help you to identify the problem or to search for some more info.

I assume, that pygame AND tk require both their own event loop.

I assume, that you start the TK window from pygame and therefore in the same thread.

Thus the pygame event loop will be stopped until the TK window is destroyed and will give control back to the pygame event loop.


One solution could be, that you start the pygame part and the TK part of your application from different threads and let them communicate for example via a threading.Queue or a similar mechanism.

Alternatively you can check, whether TK or pygame have a function , that allows to call one iteration through their even loop and whether the other frame work allows to add a call to its even loop.

Please read the doc carefully whether either pygame or TK must  be run in the main thread.


Good luck
0
 

Author Closing Comment

by:tmonteit
ID: 35161955
Spot on!  With your threading advice, I made it work.  Thanks!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now