gpt4 book ai didi

python - python init 函数中 master 和 master=none 的用途是什么?

转载 作者:行者123 更新时间:2023-12-01 05:39:12 25 4
gpt4 key购买 nike

我认为原因与我得到的 self 相似。为什么master在那里?另外,为什么有时是 master,有时是 master = none?

例如

class Application(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.grid()
self.createWidgets()

来自 Tkinter 8.5 引用:John W. Shipman 的 Python GUI。另外,该文档使用 python2,而我将使用 python3。我需要师傅吗?更多问题我尝试在 master 之后添加自定义参数,它说我无法在默认之后添加非默认参数,我应该如何修复?默认参数 self 不是必须是第一个吗?

def __init__(self, master=None,inputDict):
tk.Frame.__init__(self, master)
self.grid(sticky=tk.N+tk.S+tk.E+tk.W)
self.createWidgets()
def createWidgets(self,inputDict):
top=self.winfo_toplevel()
top.rowconfigure(0, weight=1)
top.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
tempDict = {}
for k,v in inputDict.items():
if 1<=v[0]<=3:
tempDict[k] = static_keys(*v[1:])
elif v[0] ==4:
tempDict[k] = dynamic_keys(*v[1:])
elif v[0]==5:
tempDict[k] = key_labels(*v[1:])
return tempDict

最佳答案

您的Application类是tk.Frame的子类。 master 参数是父窗口小部件,它是一个可选参数(默认情况下为 none),将传递给 Application 的新实例> 初始化时的类。

Take a look here for more info .

关于python - python init 函数中 master 和 master=none 的用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18067915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com