Tkinter มีฟังก์ชันและคุณสมบัติในตัวมากมาย ซึ่งสามารถใช้เพื่อขยายฟังก์ชันการทำงานภายในของแอปพลิเคชัน ป๊อปอัปใน Tkinter ถูกสร้างขึ้นโดยการกำหนดกล่องข้อความ ในการทำงานกับกล่องข้อความป๊อปอัป คุณต้องนำเข้าแพ็คเกจกล่องข้อความใน Tkinter ก่อนโดยใช้คำสั่ง "นำเข้า tkinter.messagebox ".
ตัวอย่าง
ในตัวอย่างนี้ เราจะสร้างป๊อปอัปของกล่องข้อความพร้อมคำถาม เมื่อคลิกตัวเลือกใดตัวเลือกหนึ่ง ระบบจะเปลี่ยนเส้นทางผู้ใช้ไปยังการดำเนินการที่เกี่ยวข้อง
# Import the required libraries
from tkinter import *
import tkinter.messagebox
# Create an instance of Tkinter Frame
win = Tk()
# Set the geometry of Tkinter Frame
win.geometry("700x350")
def open_win():
out = tkinter.messagebox.askquestion('Prompt', 'Do you want to Continue?')
if out == 'yes':
Label(win, text="Thank You for your Response!", font=('Helvetica 22 bold')).pack(pady=40)
else:
win.destroy()
# Create a Button
button = Button(win, text="Click Me", command=open_win, font=('Helvetica 14 bold'), foreground='OrangeRed3',background="white")
button.pack(pady=50)
win.mainloop() ผลลัพธ์
ในการรันโค้ดข้างต้น มันจะแสดงหน้าต่างต่อไปนี้ -

ตอนนี้ให้คลิกปุ่ม "คลิกฉัน" มันจะแสดงกล่องข้อความที่มีคำถาม

จากนั้นคลิกปุ่ม "ใช่" ในกล่องข้อความ มันจะแสดงหน้าต่างต่อไปนี้ -
