[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to Integrate PyGame with TK?

Posted on 2011-03-08
2
Medium Priority
?
484 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
[X]
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
2 Comments
 
LVL 17

Accepted Solution

by:
gelonida earned 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month12 days, 22 hours left to enroll

650 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