0

This code opens a message box on the first window. But I want to open the message box on the second window.

    From tkinter import * 
    From tkinter import messagebox as m
    Def b():
        A=m.askquestion (" question ","really want to go back")
        if(A=1):
            R2.destroy()
    Def a():
        global R2
        R2=Toplevel()
        Label(R2,text='This is second window').pack()

        Button(R2 ,text='back',command=b).pack()
    Def c():
        global Root
        Root=Tk()
        Button(root, text='next',command=a).pack()
    c()

I'm looking for any suggestions about how to open the message box on the second window.

Tedinoz
  • 5,911
  • 3
  • 25
  • 35
  • 1
    Does this answer your question? [Python 3 Tkinter - Messagebox with a toplevel as master?](https://stackoverflow.com/questions/17910866/python-3-tkinter-messagebox-with-a-toplevel-as-master) – Dan Getz Nov 18 '19 at 07:18

1 Answers1

-1

There is a solution very easy: you have to give the parent to messagebox:

    From tkinter import * 
    From tkinter import messagebox as m
    Def b():
        A=m.askquestion (" question ","really want to go back", parent = R2)
        if(A=1):
            R2.destroy()
    Def a():
        global R2
        R2=Toplevel()
        Label(R2,text='This is second window').pack()

        Button(R2 ,text='back',command=b).pack()
    Def c():
        global Root
        Root=Tk()
        Button(root, text='next',command=a).pack()
    c()