python中frame是什么意思_python-Tkinter中的Frame类的目的是什么?

下面的代码将构建一个基本的按钮GUI

from tkinter import *

class App:

def __init__(self, master):

frame = Frame(master)

frame.pack()

self.button = Button(frame,

text="QUIT", fg="red",

command=quit)

self.button.pack(side=LEFT)

self.slogan = Button(frame,

text="Hello",

command=self.write_slogan)

self.slogan.pack(side=LEFT)

def write_slogan(self):

print("Tkinter is easy to use!")

root = Tk()

app = App(root)

root.mainloop()

但是,即使我取消了Frame类并将其替换为master类,它也会显示相同的结果!

from tkinter import *

class App:

def __init__(self, master):

#frame = Frame(master)

#frame.pack()

self.button = Button(master,

text="QUIT", fg="red",

command=quit)

self.button.pack(side=LEFT)

self.slogan = Button(master,

text="Hello",

command=self.write_slogan)

self.slogan.pack(side=LEFT)

def write_slogan(self):

print("Tkinter is easy to use!")

root = Tk()

app = App(root)

root.mainloop()

如果要获得相同的结果,为什么添加Frame类如此重要?

解决方法:

Why is it so important to add the Frame class if we are going to get the same results anyway?

在您的特定示例中,创建框架没有意义.

What is the purpose of the Frame class in Tkinter?

目的是充当要作为逻辑单元对待的一组小部件的容器.

例如,传统的应用程序可能在顶部具有工具栏,在左侧具有导航面板,在主区域中可能在底部具有状态栏.您可能会使用一个框架来包含工具栏中的所有小部件,使用一个框架来包含状态栏中的所有小部件,并使用另一个框架来包含导航窗格中的小部件.

标签:tkinter,python

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值