Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to Integrate PyGame with TK?

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
High Bandwidth Usage 6 75
Upgrade BIOS / EUFI at Scale 4 55
expand ext4 on centos 6 5 37
Apache module 5 44
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…
Fine Tune your automatic Updates for Ubuntu / Debian
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.

809 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