0

此代码在第一个窗口上打开一个消息框。但我想在第二个窗口上打开消息框。

    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()

我正在寻找有关如何在第二个窗口上打开消息框的任何建议。

4

1 回答 1

-1

有一个非常简单的解决方案:您必须将父级提供给消息框:

    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()
于 2019-12-03T20:18:18.253 回答