ไลบรารี Tkinter มีฟังก์ชันและเมธอดในตัวมากมาย ซึ่งสามารถใช้เพื่อนำส่วนการทำงานของแอปพลิเคชันไปใช้ เราสามารถใช้ กล่องข้อความ โมดูลใน Tkinter เพื่อสร้างกล่องโต้ตอบป๊อปอัปต่างๆ กล่องข้อความ คุณสมบัติมีหน้าต่างป๊อปอัปในตัวประเภทต่างๆ ที่ผู้ใช้สามารถใช้ในแอปพลิเคชันของตนได้
หากคุณต้องการแสดงข้อผิดพลาด กล่องข้อความ ในแอปพลิเคชันของคุณ คุณสามารถใช้ showerror("Title", "Error Message") กระบวนการ. วิธีนี้สามารถเรียกได้ด้วย กล่องข้อความ นั่นเอง
ตัวอย่าง
# Import the required libraries
from tkinter import *
from tkinter import messagebox
# Create an instance of tkinter frame or window
win = Tk()
# Set the size of the tkinter window
win.geometry("700x350")
# Define a function to show the error message
def on_click():
messagebox.showerror('Python Error', 'Error: This is an Error Message!')
# Create a label widget
label = Label(win, text="Click the button to show the message ",
font=('Calibri 15 bold'))
label.pack(pady=20)
# Create a button to delete the button
b = Button(win, text="Click Me", command=on_click)
b.pack(pady=20)
win.mainloop() ผลลัพธ์
เมื่อคุณเรียกใช้โค้ดข้างต้น จะแสดงวิดเจ็ตปุ่มและป้ายกำกับในหน้าต่าง คลิกปุ่มเพื่อแสดงข้อความแสดงข้อผิดพลาด
