Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Message Box in Python

Is there a UI library to create a message box or input box in python?

like image 332
Mohit Ranka Avatar asked Nov 02 '08 21:11

Mohit Ranka


People also ask

How do I show a pop up message in Python?

In order to create a Python popup message, you can use Tkinter message prompts. First, you need to import the Tkinter package to use this method. The Tkinter message box module offers different options and configurations.


4 Answers

Your best bet is the tkMessageBox module, which should work on all systems (as Python will typically come with Tkinter).

If you can restrict yourself to a specific operating system, better choices might be available.

like image 197
Martin v. Löwis Avatar answered Nov 07 '22 07:11

Martin v. Löwis


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

You can get EasyGui here: http://easygui.sourceforge.net/

like image 20
Cassie Meharry Avatar answered Nov 07 '22 07:11

Cassie Meharry


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

like image 2
Dana the Sane Avatar answered Nov 07 '22 09:11

Dana the Sane


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
like image 1
akoc kanor Avatar answered Nov 07 '22 08:11

akoc kanor