【发布时间】:2012-01-03 01:35:22
【问题描述】:
我目前正在学习一本书,以尝试更多地了解 TkInter,因为我正在尝试改进我的 Python 3 编程。如有必要,可在此处找到文本:http://www.ferg.org/thinking_in_tkinter/all_programs.html
在标记为“tt040.py”的部分有一个示例代码,其中一部分是:
self.button1 = Button(self.myContainer1)
self.button1["text"] = "Hello, World!" ### (1)
self.button1["background"] = "green" ### (1)
self.button1.pack()
self.button2 = Button(self.myContainer1)
self.button2.configure(text="Off to join the circus!") ### (2)
self.button2.configure(background="tan") ### (2)
self.button2.pack()
self.button3 = Button(self.myContainer1)
self.button3.configure(text="Join me?", background="cyan") ### (3)
self.button3.pack()
这部分代码的解释是:
"(2)对于button2,过程与button1基本相同,但我们不是访问按钮的字典,而是使用按钮内置的“configure”方法。
(3) 对于button3,我们看到configure方法可以接受多个关键字参数,所以我们可以在一个语句中设置多个选项。”
解释的真正含义是什么?如,实际区别是什么(使用 .pack)或需要 .configure 方法? “按钮的字典”是什么意思?
【问题讨论】: