4

I'm writing a game using Pygame, and parts of the game require data input that Tk seems to be good at.

I've got some things working, but I'm finding the implementation ugly and it is becoming clear I'm not using Tkinter the way it was intended to be used.

I have various methods that create Tk windows asking for input and then destroy them so that my Pygame program can make decisions about what the next input should be.

Am I missing something? Is there a better way to get form style input?

4

1 回答 1

4

Pygame doesn't have any included form input type stuff, and there's not really a way for Tkinter and Pygame to coexist peacefully in the same window, so you have two options, if you're going to stay within Pygame:

  1. Use a third party library

Phil's Pygame utilities are a pretty good option and provide some good basic functionality like file dialogs, popups, etc. Take a look around the projects on Pygame's website, and see if anyone else's fits your specific needs better.

  1. Code them yourself

Here is a pretty good example of how you'd put together your own input methods. Buttons, lists, and such would be similar as far as event handling is concerned, just check for mouse clicks in each UI element's borders.

于 2012-05-28T08:07:36.793 回答