-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

4
  • You mean in the console, or in a GUI dialog box? Commented Jul 25, 2015 at 4: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. Commented Jul 25, 2015 at 4:02
  • 1
    See stackoverflow.com/questions/2963263/… Commented Jul 25, 2015 at 4: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. Commented Jul 25, 2015 at 4:12

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

@Ryrysmithers, is this what you were asking for? If so, please mark the answer as accepted; if not, please clarify.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.