Tkinter เป็นไลบรารี Python มาตรฐานที่ใช้ในการสร้างและพัฒนาแอปพลิเคชันที่ใช้ GUI เราสามารถสร้างแอปพลิเคชันใน Tkinter และเพิ่มวิดเจ็ตเพื่อให้แอปพลิเคชันโต้ตอบได้มากขึ้น
สมมติว่าเราต้องการแสดงกล่องโต้ตอบป๊อปอัปในแอปพลิเคชัน ในกรณีนี้ เราสามารถใช้ กล่องข้อความ . ในตัว โมดูลใน tkinter ช่วยให้เราสามารถแสดงกล่องโต้ตอบต่างๆ เช่น ข้อผิดพลาด กล่องข้อมูล กล่องยืนยัน ฯลฯ
ตัวอย่าง
ในตัวอย่างนี้ เราได้สร้างปุ่ม ซึ่งเมื่อคลิกแล้ว จะแสดงข้อความป๊อปอัปบนหน้าจอ
# Import the required library
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
# Create an instance of tkinter frame
win=Tk()
# Set the geometry
win.geometry("700x250")
# Define a button to show the popup message box
def on_click():
messagebox.showinfo("Message", "Hey folks!")
# Add a Label widget
Label(win, text="Click the button to open a popup", font=('Georgia 13'))
# Create a button to open the popup dialog
ttk.Button(win, text="Open Popup", command=on_click).pack(pady=30)
win.mainloop() ผลลัพธ์
การเรียกใช้โค้ดด้านบนจะแสดงหน้าต่างพร้อมปุ่มสำหรับเปิดกล่องโต้ตอบ

คลิกปุ่มเพื่อแสดงกล่องโต้ตอบป๊อปอัปบนหน้าจอ
