200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > python调用函数出现未定义_python中函数调用中的“未定义”参数

python调用函数出现未定义_python中函数调用中的“未定义”参数

时间:2023-04-22 17:37:13

相关推荐

python调用函数出现未定义_python中函数调用中的“未定义”参数

每当我用Tkinter在python中编程时,代码如下所示:from Tkinter import *

class GUI():

def __init__(self, master):

self.master = master # master is an instance of Tk

self.master.title("") # set the name of the window

self.frame = Frame(self.master, width=800, height=500, bg="#eeeeee")

# 800, 500 and "#eeeeee" are examples of course

self.frame.pack()

self.canvas = Canvas(self.frame, width=800, height=500, bg="ffffff")

self.canvas.place(x=0, y=0)

#mostly there are some other widgets

# here are obviously other methods

def main():

root = Tk()

app = GUI(root) # root and app.master are synonyms now

app.master.mainloop()

if __name__ == '__main__':

main()

我的问题是,我真的不明白Frame(width=800, height=500)或place(x=0, y=0)为什么工作:我没有定义参数height、width、x和{}。查看Tkinter-模块中的代码,函数需要一个名为*args或**kw的参数。我知道如何使用它们(至少足够开发一些小型应用程序),但我不知道如何定义一个使用这些参数的函数。我觉得我对python的这一部分知之甚少,尽管我可以使用它。

所以我的问题是:

如何定义函数,使用以下语法调用:

^{pr2}$

我不需要知道如何使一个函数接受不同数量的参数(结合我的问题),但它也可以。在

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。