0

I'm a little confused as to how this function works. I want to have the master window be a separate toplevel I create.

tk.NoDefaultRoot()
root = tk.Tk()
root.master = tk.Toplevel()
root.mainloop()

If I attempt to do something like this I get an attribute error:

AttributeError: 'NoneType' object has no attribute 'tk'

Is there a way to do something like this?

Robert Criqui
  • 208
  • 3
  • 11

1 Answers1

2

When default root feature is enabled (it is default enabled) and you create a widget without passing the parent argument, it will use the default root created either implicitly or explicitly.

However if default root feature is disabled by executing tk.NoDefaultRoot(), then the default root will not be used or created for you.

You need to pass the root instance to Toplevel() explicitly: tk.Toplevel(root).

acw1668
  • 40,144
  • 5
  • 22
  • 34
  • Ah, okay that makes sense. I thought that NoDefaultRoot would prevent the program from creating the main window, but from your explanation I can see that's not what it's intended for. I'll follow Bryan's answer here: [Correct way to hide main window](https://stackoverflow.com/questions/1406145/how-do-i-get-rid-of-python-tkinter-root-window) – Robert Criqui Jan 14 '21 at 13:48