每当我用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}$
我不需要知道如何使一个函数接受不同数量的参数(结合我的问题),但它也可以。在