简体   繁体   中英

Tkinter - create new window on top of root window

How do I create a new tkinter root window on top of the main root window that prevents you from accessing the main window until you close the secondary window?

Here is the code that I've written so far (in python 3.6):

from tkinter import *
root = Tk()
root.geometry('600x400+0+0')

def new_page():
    rootB = Tk()

btnNP = Button(root, padx=1, pady=2, fg='black',relief='raise',font=
('garamond',10, 'italic', 'bold'),
             text='New Page', bg='blue', command=new_page)
btnNP.place(x=100, y=300)

text1 = Text(root, bd=5, height=1, width=14, bg='pink')
text1.place(x=100, y=250)

root.mainloop()

I use Toplevel instead of a new root

def New_page():
    popup = Toplevel()
    popup.grab_set()

this should do the trick

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM