zl程序教程

您现在的位置是:首页 >  后端

当前栏目

python界面Tkinter编程(tkMessageBox对话框使用)

Python编程 界面 对话框 tkinter 使用
2023-09-11 14:22:29 时间

1. 前言

tkMessageBox是Tkinter中常用的对话框控件,可以和方便实现相关对话框的弹出等,类似于MFC中的MessageBox。在Tkinter中定义了多种类型的对话框,其基本的调用形式为:

tkMessageBox.xxxxx(title, message, options)

其中的title自然是对话框的标题,message是显示的内容,对于options

属性含义
default设置默认的选择项,有tkMessageBox: CANCEL, IGNORE, OK, NO, RETRY, or YES
icon设置对话框的图标,有tkMessageBox: ERROR, INFO, QUESTION, WARNING
parent指定对话框的父窗口

2. tkMessageBox中的对话框类型

2.1 示例代码

tkMessageBox.askokcancel('askokcancel', 'hello', parent=root_window,)
tkMessageBox.askquestion('askquestion', 'hello', parent=root_window)
tkMessageBox.askretrycancel('askretrycancel', 'hello', parent=root_window)
tkMessageBox.askyesno('askyesno', 'hello', parent=root_window)
tkMessageBox.showinfo('showinfo', 'hello', parent=root_window)
tkMessageBox.showerror('showerror', 'hello', parent=root_window)
tkMessageBox.showwarning('showwarning', 'hello', parent=root_window)

2.2 结果

这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述