在 python 中向用户显示消息

Show user a message in python

在这里快速提问。有没有一种非常简单的方法可以像 python 中的文本框一样向用户显示消息?我只需要预先输入一个字符串,这样我就可以在循环运行后显示消息。谢谢!

编辑:只是 Windows 8.1 和直线 python 2.7

如果我认为您希望 window 让用户输入一些文本,然后将其显示为消息框,那么您需要两个模块,tkMessageBoxTinker,Python 2.7+ 中的两个标准模块。

以下记录的代码执行上述操作

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