Tkinter 中的不同消息 - Python

pythonserver side programmingprogramming

Tkinter 是 Python 的 GUI 模块。它使用各种消息显示选项,这些选项响应用户操作或正在运行的程序的状态变化。消息框类用于显示各种消息,如确认消息、错误消息、警告消息等。

示例 1

以下示例显示了消息的显示,其中背景颜色、字体大小和颜色等可自定义。

import tkinter as tk
main = tk.Tk()

key = "the key to success is to focus on goals and not on obstacles"

message = tk.Message(main, text = key)
message.config(bg='white', font=('times', 32, 'italic'))

message.pack()
tk.mainloop()

运行上述代码,我们得到以下图像 −

示例 2

在下面的示例中,我们看到了许多标准操作的显示,例如显示信息或显示错误等。messagebox 类有不同的函数用于显示各种消息类别。

问题框

这是通过使用askquestion()函数实现的。

示例

from tkinter.messagebox import *
print(askquestion("Question", "Proceed to next Step?"))

运行上述代码得到以下结果 −

重试框

这是通过使用 askretrycancel()函数实现的。

from tkinter.messagebox import *
print(askretrycancel("Retry", "Try Again?"))

运行上述代码得到以下结果 −

错误框

这是通过使用showerror()函数实现的。

from tkinter.messagebox import *
print(showerror("Error", "Error in checkout"))

运行上述代码得到以下结果 −

警告框

这是通过使用 askretrycancel()函数实现的。

from tkinter.messagebox import *
print(showwarning("Warning", "This may result in delay !"))

运行上述代码得到以下结果 −


相关文章