Simplest way to get initial text input in pygame
So, Iv'e got a pygame application. Right now, it takes a command line argument to specify which display to show the main screen on. However, I'm running it on windows, where it's hard to specify command line input to a graphical application.
So, I'd like to have a very very very simple dialog box which pops up, prompts the user for an integer, then closes. My research has shown that pygame can't do a dialog box like this, and I can't get input in a pygame window, because the program doesn't know yet which monitor to draw the pygame window to.
So, my question is, what is the simplest way to create a dialog box for input? I've looked into wx and tkinter. I could use either of them, but what I'm wondering is, but I want to import the least number of extra toolkits. i.e. I don't want to have to start the wx main loop just so I can make 1 dialog, then close it, then start a whole new pygame window.
I know how to do this in wx, so I'm mostly looking for advice/ideas as to which toolkit would be simplest, as oppo开发者_StackOverflow社区sed to instruction on how to actually do it (though that's always nice too).
Since tkinter is built into Python, it might be better. I prefer wx, but if you just want a few dialogues, tkinter is fine.
You could also just try raw_input('type "1" for low res, "2" for high res')
. I think it brings up a dialog window in Windows.
A better solution might be to just assume that you are going on the first monitor. In game, you can have a configuration option, which you save to a config file to be read next time, which the user can select. If the user decides that your application is on the wrong monitor, you should just inform them that they will have to restart your application for the change to take effect.
You can also put conspicuous notes in your documentation explaining what the config option is and how to set it in case users want (or need) to do so before launching the application the first time.
Edit:
If you're dead set against that, you could write your application as two applications, something like this:
try:
configfile = file("path/to/config")
except IOError:
import Tkinter
# make a tkinter interface to set the screen options
configfile = file("path/to/config", "w)
configfile.write(options)
os.execl("path/to/self")
else:
import pygame
screen = read_config(configfile)
# your pygame code
This is probably an ugly way to do it, but what I ended up doing was using the win32 extensions. I found a base class here:
http://www.java2s.com/Open-Source/Python/Windows/pyExcelerator/pywin32-214/pythonwin/pywin/mfc/dialog.py.htm
I was already using them, so I didn't need to import any new packages. That said, this is probably not a good general solution...
精彩评论