Solved

How to Integrate PyGame with TK?

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
fedora linux on laptop - setup sendmail - or some kind of email 5 66
LogmeIn using Linux Ubuntu 16.04 6 117
HOw To Install Docker on VMware Workstation 19 354
IMAP copying tool 14 49
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 how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

730 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