Tkinter에는 이미 Python으로 구현된 많은 내장 함수와 모듈이 있습니다. 메시지 상자 Tkinter의 모듈은 관련 기능만 사용하면 모든 응용 프로그램에서 사용할 수 있는 모듈 중 하나입니다. 이러한 패키지의 유일한 제한 사항은 MessageBox를 수정하거나 변경할 수 없다는 것입니다. 주형. 따라서 Custom Popup MessageBox를 구현하려면 다음 단계를 따르십시오.
- 버튼을 만들고 여기에 기능을 정의하는 명령을 추가합니다.
- 최상위 창을 만들고 여기에 다른 위젯을 추가하는 함수를 정의합니다.
- 최상위 창에 버튼 및 확인 레이블 텍스트 추가
- 기본 창에 대화식으로 일부 메시지를 표시하는 버튼 명령을 추가합니다.
예시
# Import required libraries
from tkinter import *
from tkinter import ttk
# Create an instance of tkinter frame
win = Tk()
# Set the window size
win.geometry("700x250")
# Define a function to implement choice function
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")
# Create a Label Text
label = Label(pop, text="Would You like to Proceed?", bg="green3", fg="white", font=('Aerial', 12))
label.pack(pady=20)
# Add a Frame
frame = Frame(pop, bg="green3")
frame.pack(pady=10)
# Add Button for making selection
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)
# Create a Label widget
label = Label(win, text="", font=('Aerial', 14))
label.pack(pady=40)
# Create a Tkinter button
ttk.Button(win, text="Click Here", command=click_fun).pack()]
win.mainloop() 출력
위의 코드를 실행하면 버튼이 있는 창이 나타납니다.

버튼을 클릭하면 사용자 정의 팝업 메시지 상자가 표시됩니다.
