Python GUI - Tkinter tkMessageBox

Python GUI - Tkinter tkMessageBox: tkMessageBox模块用于显示在您的应用程序的消息框。此模块提供了一个功能,您可以用它来显示适当的消息
 
 

tkMessageBox模块用于显示在您的应用程序的消息框。此模块提供了一个功能,您可以用它来显示适当的消息.

这些功能有些是showinfo,showwarning,showerror,askquestion,askokcancel,askyesno,askretryignore.

方法:

这里是一个简单的语法来创建这个widget:

tkMessageBox.FunctionName(title, message [, options])

参数:

  • FunctionName: 这是相应的消息框函数的名称.

  • title: 这是在一个消息框,标题栏显示的文本.

  • message: 这是要显示的文字作为消息.

  • options: 选项有替代的选择,你可以用它来定制一个标准的消息框。一些可以使用的选项是默认的。默认选项是用来指定默认的按钮,如中止,重试,或忽略在消息框中。父选项是用来指定要显示的消息框上的顶层窗口.

If the standard message boxes are not appropriate, you can pick the closest alternative (askquestion, in most cases), and use options to change it to exactly suit your needs. You can use the following options (note that messageand title are usually given as arguments, not as options).

default constant

Which button to make default: ABORTRETRYIGNOREOKCANCEL,YES, or NO (the constants are defined in the tkMessageBox module).

icon (constant)

Which icon to display: ERRORINFOQUESTION, or WARNING

message (string)

The message to display (the second argument to the convenience functions). May contain newlines.

parent (widget)

Which window to place the message box on top of. When the message box is closed, the focus is returned to the parent window.

title (string)

Message box title (the first argument to the convenience functions).

type (constant)

Message box type; that is, which buttons to display:ABORTRETRYIGNOREOKOKCANCELRETRYCANCELYESNO, orYESNOCANCEL.

  • showinfo()

Python GUI - Tkinter tkMessageBox

  • showwarning()

Python GUI - Tkinter tkMessageBox

  • showerror ()

Python GUI - Tkinter tkMessageBox

  • askquestion()

Python GUI - Tkinter tkMessageBox

  • askokcancel()

Python GUI - Tkinter tkMessageBox

  • askyesno ()

Python GUI - Tkinter tkMessageBox

  • askretrycancel ()

Python GUI - Tkinter tkMessageBox

例子:

自行尝试下面的例子:

import Tkinter
import tkMessageBox top = Tkinter.Tk()
def hello():
tkMessageBox.showinfo("Say Hello", "Hello World") B1 = Tkinter.Button(top, text = "Say Hello", command = hello)
B1.pack() top.mainloop()

这将产生以下结果:

Python GUI - Tkinter tkMessageBox 

不显示window root窗口

import Tkinter
import tkMessageBox top = Tkinter.Tk()
top.withdraw()
tkMessageBox.askyesno("Say Hello", "Hello World")

Python GUI - Tkinter tkMessageBox  

  

上一篇:【APP设计利器】Sketch 41 Mac中文破解版(含汉化插件)


下一篇:python界面Tkinter编程(tkMessageBox对话框使用)