Can anyone tell me if pygame and Tkinter can work together?

Nathan Pinno falcon3166 at hotmail.com
Tue Nov 15 23:45:01 EST 2005


Sounds good, I'll give it a try and see what happens, and report back about
my results. 


Nathan Pinno,
Owner/operator of The Web Surfer's Store.
http://www.the-web-surfers-store.com/
MSN Messenger: falcon3166 at hotmail.com
Yahoo! Messenger: spam_swatter31
AIM: f3mighty
ICQ: 199020705  

-----Original Message-----
From: jepler at unpythonic.net [mailto:jepler at unpythonic.net] 
Sent: November 15, 2005 8:47 PM
To: Nathan Pinno
Cc: python-list at python.org
Subject: Re: Can anyone tell me if pygame and Tkinter can work together?

On Tue, Nov 15, 2005 at 06:33:40PM -0700, Nathan Pinno wrote:
> Thanks. I was going to use TKInter to pop up a message box, then use 
> pygame to run the game and display the score on the playing surface. 
> Is this still possible (I'm using Python 2.4.1 and Pygame 1.7.0 on 
> WinXP with Service Pack 2)?

This is more likely to work than the scenario I first considered, where both
GUI libraries would be in use at the same time.

With my understanding of how X works, and my knowledge of Tk, you'd probably
be successful if what you want to do is first use GUI Library A, and then
GUI Library B.  This resolves the issue with XSetErrorHandler, for instance,
because you'll be completely done with Library A at the time you call the
initialization routines of Library B.  It also resolves the event loop
problem, because you never need to allow Libraries A and B to receive events
during the same phase of the program.

I don't know anything about Windows, and I haven't actually given this
scenario a try on Linux either, so it's still all idle speculation on my
part.  Actual experimentation on your part wouldn't be that hard, though.
Just write the simplest possible Tk program as a callable function 't()' and
the simplest possible pygame program as a callable function 'p()', and then
see what happens when you run them back to back:
	def t():
		import Tkinter
		t = Tkinter.Tk()
		Tkinter.Button(t, command = t.destroy).pack()
		t.mainloop()
	def p():
		likewise
	t()
	p()

Jeff



More information about the Python-list mailing list