I want the simplest possible way to pop up simple dialogs in Python scripts. Ideally, the solution would:
@ endolith, re: zenity for Windows.
Hi,
I repackaged "Zenity for Windows" and included the correct GTK-theme file. It looks much better now. :) It is now available for download: http://www.placella.com/software/zenity/
Screenshot:
(source: placella.com)
Peace, Rouslan
TkInter is usually supplied with Python
# File: hello1.py
from Tkinter import *
root = Tk()
w = Label(root, text="Hello, world!")
w.pack()
root.mainloop()
If you want something more native looking, you'll have to install something like wxpython
The PyMsgBox module does almost exactly this. It uses the built-in tkinter module for its message box functions that follow the naming conventions of JavaScript: alert(), confirm(), prompt() and password() (which is prompt() but uses * when you type). These function calls block until the user clicks an OK/Cancel button. It's a cross-platform, pure Python module with no dependencies.
Native look-and-feel message boxes will be available in a future version.
Install with: pip install PyMsgBox
Sample usage:
>>> import pymsgbox
>>> pymsgbox.alert('This is an alert!', 'Title')
>>> response = pymsgbox.prompt('What is your name?')
Full documentation at http://pymsgbox.readthedocs.org/en/latest/
pyglet is another alternative, though it may not be the simplest. that being said, it's cross-platform and only depends on python, so there's no external dependencies. that fact alone can be reason enough to use it over others.
and all it can handle multimedia pretty easily as well, pretty handy if you want to display an image or video or something.
the example below is from the documentation...
#!/usr/bin/python
import pyglet
window = pyglet.window.Window()
label = pyglet.text.Label('Hello, world',
font_name='Times New Roman',
font_size=36,
x=window.width/2, y=window.height/2,
anchor_x='center', anchor_y='center')
@window.event
def on_draw():
window.clear()
label.draw()
pyglet.app.run()