Why are multiple instances of Tk discouraged?

后端 未结 3 2086
心在旅途
心在旅途 2020-11-21 09:55

Consider below example:

import tkinter as tk

root = tk.Tk()
root.title(\"root\")

other_window = tk.Tk()
other_window.title(\"other_window\")

root.mainloop         


        
3条回答
  •  粉色の甜心
    2020-11-21 10:48

    The best reference I've found so far is this section in the tkinterbook.

    In the simple examples we’ve used this far, there’s only one window on the screen; the root window. This is automatically created when you call the Tk constructor

    and

    If you need to create additional windows, you can use the Toplevel widget. It simply creates a new window on the screen, a window that looks and behaves pretty much like the original root window

    My take on it is that a Tk instance creates a Toplevel widget, plus things like the mainloop, of which there should be only one.

提交回复
热议问题