简体   繁体   中英

what the different Tk() and Frame()

1.

import tkinter as tk
root = tk.Tk()
root.mainloop()

2.

import tkinter as tk
root = tk.Tk()
app = tk.Frame(root)
app.mainloop()

after run this, it seems the same.

And any advantage when use tk.Frame() ?

Tk creates the root window. Every tkinter application must have a root window. When you instantiate it you also create a tcl interpreter that is used by tkinter.

Frame is just a widget, designed to be a container for other widgets. It cannot act as a standalone window. An instance of Frame cannot exist without an instance of Tk -- if you don't explicitly create an instance of Tk , one will be created for you.

In your example there is no advantage to using frame because you a) don't make it visible with pack , place , or grid , and b) you don't put anything in it.

There are many advantages to using frames, but the main one is that it makes it easy to organize your widgets into logical groups.

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