簡體   English   中英

有沒有辦法在 tkinter 的頂層創建消息框?

[英]Is there a method to create a messagebox in top-level in tkinter?

此代碼在第一個 window 上打開一個消息框。 但我想打開第二個 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()

我正在尋找有關如何在第二個 window 上打開消息框的任何建議。

有一個非常簡單的解決方案:您必須將父級提供給消息框:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM