Tkinter Simulation dialog using Toplevel window
Implementation
This program will execute with a Click Me
button, when this button is clicked a random number will generate Yes, No, Exit strings, which will appear in the Toplevel window.
from tkinter import *
import random
cnt = 0
root = Tk()
root.title("apidemos.com")
root.geometry("300x180")
msgYes, msgNo, msgExit = 1,2,3
def MessageBox():
msgType = random.randint(1,3) # Generate a random integer in the range of 1 and 3, including 1 and 3
if msgType == msgYes:
labTxt = "Yes"
elif msgType == msgNo:
labTxt = "No"
elif msgType == msgExit:
labTxt = "Exit"
tl = Toplevel()
tl.geometry("300x180")
global cnt
tl.title("Message Box"+str(cnt))
cnt += 1
Label(tl,text=labTxt).pack(fill=BOTH,expand=True)
btn = Button(root,text="Click Me",command = MessageBox)
btn.pack()
root.mainloop()
Output: