如何在 Tkinter 中创建消息框?
在某个应用程序中,我们可以使用消息框方法创建消息框。以下是我们可以为某个应用程序创建的消息框的列表:
showinfo() - 在屏幕上显示一般消息。
showwarning() - 向用户显示警告。
showerror() - 显示错误消息。
askquestion() - 通过消息框询问用户。
asktocancel() - 显示取消操作的信息。
askretrycancel() - 显示提示用户是否重试的消息。
示例
在这个示例中,我们将创建一个应用程序,点击按钮后将显示一个信息消息框。
#Import required libraries
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
#Create an instance of tkinter frame
win= Tk()
#Define the geometry of the window
win.geometry("750x250")
#Define a function to show the messagebox
def handler():
messagebox.showinfo("Message", "You have clicked a Button")
#Create a Label
Label(win, text= "Click the below button", font=('Helvetica 16
underline')).pack(pady=20)
#Create a Button
ttk.Button(win, text= "Click", command= handler).pack(pady=30)
win.mainloop()输出
当我们点击按钮时,将显示一个消息框:
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP