[英]Is there a method to create a messagebox in top-level in tkinter?
This code opens a message box on the first window.此代码在第一个 window 上打开一个消息框。 But I want to open the message box on the second 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()
I'm looking for any suggestions about how to open the message box on the second window.我正在寻找有关如何在第二个 window 上打开消息框的任何建议。
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.