Solved

How to Integrate PyGame with TK?

Posted on 2011-03-08
2
462 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

911 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

22 Experts available now in Live!

Get 1:1 Help Now