用python向用户显示消息

用python向用户显示消息,python,text,output,Python,Text,Output,这里有个简单的问题。有没有一种像python中的文本框那样简单地向用户显示消息的方法?我只需要事先输入一个字符串,这样我就可以在循环运行后显示消息。谢谢 编辑:只需Windows 8.1和straight python 2.7如果我认为您需要一个窗口让用户输入一些文本,然后将其显示为消息框,那么您需要两个模块,tkMessageBox和Tinker,这是python 2.7+中的两个标准模块 以下文档化代码实现了上述功能 from Tkinter import * import tkMessag

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


编辑:只需Windows 8.1和straight python 2.7

如果我认为您需要一个窗口让用户输入一些文本,然后将其显示为消息框,那么您需要两个模块,
tkMessageBox
Tinker
,这是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

你是说在控制台中,还是在GUI对话框中?哪个操作系统,哪个GUI工具包?窗户?雨衣?Linux?无论哪种方式,这都是重复的,请阅读与操作系统和GUI工具包相关的问题。请参阅GUI中的“首选”?那么你愿意接受控制台解决方案?与中一样,您不熟悉
print
语句吗?也许你应该看一看那些书。@Ryrysmithers,这是你要的吗?如果是,请将答案标记为已接受;如果没有,请澄清。