Python Message Box

Is there a user interface library for creating a message box or input field in python?

+6
python user-interface user-controls
Nov 02 '08 at 21:22
source share
5 answers

It is best to use the tkMessageBox module, which should work on all systems (since Python usually ships with Tkinter).

If you can limit yourself to a specific operating system, more affordable options may be available.

+11
Nov 02 '08 at 21:26
source share

Simple message boxes and input fields can be created using EasyGui, a small library that uses Tkinter that comes with Python.

Here you can get EasyGui: http://easygui.sourceforge.net/

+3
Nov 03 '08 at 3:16
source share

I heard good things about wx python, which is also multi-platform.

+2
Nov 02 '08 at 22:58
source share

from Tkinter

import * import os class Dialog(Toplevel): def __init__(self, parent, title = None): Toplevel.__init__(self, parent) self.transient(parent) if title: self.title(title) self.parent = parent self.result = None body = Frame(self) self.initial_focus = self.body(body) body.pack(padx=5, pady=5) self.buttonbox() self.grab_set() if not self.initial_focus: self.initial_focus = self self.protocol("WM_DELETE_WINDOW", self.cancel) self.geometry("+%d+%d" % (parent.winfo_rootx()+50, parent.winfo_rooty()+50)) self.initial_focus.focus_set() self.wait_window(self) # # construction hooks def body(self, master): # create dialog body. return widget that should have # initial focus. this method should be overridden pass def buttonbox(self): # add standard button box. override if you don't want the # standard buttons box = Frame(self) w = Button(box, text="OK", width=10, command=self.ok, default=ACTIVE) w.pack(side=LEFT, padx=5, pady=5) w = Button(box, text="Cancel", width=10, command=self.cancel) w.pack(side=LEFT, padx=5, pady=5) self.bind("<Return>", self.ok) self.bind("<Escape>", self.cancel) box.pack() # # standard button semantics def ok(self, event=None): if not self.validate(): self.initial_focus.focus_set() # put focus back return self.withdraw() self.update_idletasks() self.apply() self.cancel() def cancel(self, event=None): # put focus back to the parent window self.parent.focus_set() self.destroy() # # command hooks def validate(self): return 1 # override def apply(self): pass # override 
+1
Dec 30 '11 at 11:21
source share

The latest version of the message box is the prompt_box module. It has two packages: alert and message. A message gives you more control over the window, but takes longer to enter.

Example warning code:

 import prompt_box prompt_box.alert('Hello') #This will output a dialog box with title Neutrino and the #text you inputted. The buttons will be Yes, No and Cancel 

Example message code:

 import prompt_box prompt_box.message('Hello', 'Neutrino', 'You pressed yes', 'You pressed no', 'You pressed cancel') #The first two are text and title, and the other three are what is #printed when you press a certain button 
0
Jun 04 '19 at 19:42
source share



All Articles