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

jepler at unpythonic.net jepler at unpythonic.net
Tue Nov 15 22:46:40 EST 2005


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20051115/85c1683d/attachment.sig>


More information about the Python-list mailing list