Tkinter में कई इनबिल्ट फंक्शन और मॉड्यूल हैं जो पहले से ही Python में इम्प्लीमेंटेड हैं। Tkinter में MessageBox मॉड्यूल उनमें से एक है जिसका उपयोग किसी भी एप्लिकेशन में केवल इसके संबद्ध फंक्शन का उपयोग करके किया जा सकता है। इन पैकेज की एकमात्र सीमा यह है कि हम MessageBox टेम्पलेट को संशोधित या बदल नहीं सकते। इसलिए, एक कस्टम पॉपअप MessageBox इम्प्लीमेंट करने के लिए, हम इन चरणों का पालन कर सकते हैं:
- एक बटन बनाएं और इसमें एक फंक्शन परिभाषित करने के लिए कमांड जोड़ें।
- एक Toplevel विंडो बनाने और उसमें अन्य विजेट जोड़ने के लिए एक फंक्शन परिभाषित करें।
- Toplevel विंडो में बटन और कन्फर्मेशन लेबल टेक्स्ट जोड़ें।
- मुख्य विंडो में इंटरैक्टिव रूप से कुछ मैसेज प्रदर्शित करने के लिए बटन कमांड जोड़ें।
उदाहरण
# आवश्यक लाइब्रेरी इम्पोर्ट करें
from tkinter import *
from tkinter import ttk
# Tkinter फ्रेम का इंस्टेंस बनाएं
win = Tk()
# विंडो का आकार सेट करें
win.geometry("700x250")
# विकल्प लागू करने के लिए फंक्शन परिभाषित करें
def choice(option):
pop.destroy()
if option == "yes":
label.config(text="Hello, How are You?")
else:
label.config(text="You have selected No")
def click_fun():
global pop
pop = Toplevel(win)
pop.title("Confirmation")
pop.geometry("700x250")
pop.config(bg="green3")
# लेबल टेक्स्ट बनाएं
label = Label(pop, text="Would You like to Proceed?", bg="green3", fg="white", font=('Aerial', 12))
label.pack(pady=20)
# एक फ्रेम जोड़ें
frame = Frame(pop, bg="green3")
frame.pack(pady=10)
# चयन के लिए बटन जोड़ें
button1 = Button(frame, text="Yes", command=lambda: choice("yes"), bg="green")
button1.grid(row=0, column=1)
button2 = Button(frame, text="No", command=lambda: choice("no"), bg="green")
button2.grid(row=0, column=2)
# लेबल विजेट बनाएं
label = Label(win, text="", font=('Aerial', 14))
label.pack(pady=40)
# Tkinter बटन बनाएं
ttk.Button(win, text="Click Here", command=click_fun).pack()
win.mainloop()आउटपुट
उपरोक्त कोड चलाने पर एक बटन वाली विंडो दिखाई देगी।

जब हम बटन पर क्लिक करते हैं, तो यह एक कस्टम पॉपअप मैसेजबॉक्स दिखाएगा।
