Tkinter เป็นไลบรารี Python ยอดนิยมสำหรับสร้างและพัฒนาแอปพลิเคชัน มีเมธอดและฟังก์ชันต่างๆ ที่ใช้เพิ่มฟีเจอร์หลายอย่างในแอปพลิเคชัน ด้วย Tkinter เราสามารถสร้าง Dialogue Boxes และ Widgets อื่นๆ ได้
ในบทความนี้ เราจะดูวิธีสร้าง Simple Message Box ที่จะ Pop Up และแสดงข้อมูลเพื่อให้เลือกตัวเลือก
ตัวอย่าง
# Import the required libraries
from tkinter import *
from tkinter import messagebox
# Create an instance of tkinter frame or window
win = Tk()
# Set the geometry
win.geometry("700x100")
# Define the function for button
def pop_up():
messagebox.showerror("Error! Please check and correct.")
messagebox.showwarning("Warning! You can not proceed.")
# Create a button
Button(win, text="Click", command=pop_up).pack(pady=20)
# Keep Running the window
win.mainloop()
ผลลัพธ์
การรันโค้ดข้างต้นจะผลิตหน้าต่างดังนี้:

หากคุณคลิกปุ่ม "Click" Error Message ต่อไปนี้จะ Pop Up:

อีกครั้ง หากคุณคลิกปุ่ม "OK" จะ Pop Up Warning Message ต่อไปนี้:
