-4

quick question here. Is there a really easy way to show a user a message in like a text box in python? I just need to input a string beforehand so I can show the message after a loop runs. Thanks!

EDIT: Just Windows 8.1 and straight python 2.7

  • You mean in the console, or in a GUI dialog box? – smci Jul 25 '15 at 04:00
  • 1
    Which OS, and which GUI toolkit? Windows? Mac? Linux? Either way, this is a duplicate, read the questions relevant to your OS and GUI toolkit. – smci Jul 25 '15 at 04:02
  • 1
    See http://stackoverflow.com/questions/2963263/how-can-i-create-a-simple-message-box-in-python –  Jul 25 '15 at 04:10
  • "Preferably" in a GUI? So you'd be open to console solutions? As in, you're unfamiliar with the `print` statement? Perhaps you should take a look at the [official Python tutorial](https://docs.python.org/2.7/tutorial/index.html). – TigerhawkT3 Jul 25 '15 at 04:12

1 Answers1

1

If I'm correct that you want a window to let a user type in some text, then show it back as a message box, then you need two modules, tkMessageBox and Tinker, two standard modules in Python 2.7+.

The following documented code does the above

from Tkinter import *
import tkMessageBox

def getInfo():
    #This function gets the entry of the text area and shows it to the user in a message box
    tkMessageBox.showinfo("User Input", E1.get())


def quit():
    #This function closes the root window
    root.destroy()


root = Tk() #specify the root window

label1 = Label( root, text="User Input") #specify the label to show the user what the text area is about
E1 = Entry(root, bd =5) #specify the input text area

submit = Button(root, text ="Submit", command = getInfo) #specify the "submit" button that runs "getInfo" when clicked
quit_button = Button(root, text = 'Quit', command=quit) #specify the quit button that quits the main window when clicked

#Add the items we specified to the window
label1.pack()
E1.pack()
submit.pack(side =BOTTOM)
quit_button.pack(side =BOTTOM) 

root.mainloop() #Run the "loop" that shows the windows
Manuel J. Diaz
  • 1,240
  • 12
  • 20