我是蟒蛇的初学者。最近我完成了基础工作,现在我正在尝试制作一些GUI应用程序。我发现了很多使用config()和config()的情况。但是config()和config()之间有什么区别呢?
我的意思是,在什么情况下应该使用config(),在什么情况下应该使用配置()。我这里有一小部分代码。
使用配置的代码:
fontStyle = tkFont.Font(family="comic sans ms", size=15)
def zoomin_1():
fontsize=fontStyle['size']
fontStyle.configure(size=fontsize+5)
def zoomout_1():
fontsize = fontStyle['size']
fontStyle.configure(size=fontsize - 5)
def default_1():
fontStyle.configure(size=10)使用config的代码:
root.config(menu=mainmenu)
mainmenu.add_cascade(label="Edit", menu=Edit_menu)
Format_menu = Menu(mainmenu, tearoff = False)
Format_menu.add_command(label="Word Wrap", command= test_fun)
Format_menu.add_command(label="Font", command= test_fun)
root.config(menu=mainmenu)
mainmenu.add_cascade(label="Format", menu=Format_menu)如果有人能消除这种疑虑,会有很大的帮助。
发布于 2020-08-06 09:42:12
两者是完全相同的,唯一的区别是,名称上的不同,我只需要使用.config()来保存几个输入字符;-)
发布于 2022-10-15 10:17:27
找出差异的最好方法是查看tkinter的__init__.py源代码
(在我的例子中是在Thonny -Thonny\Lib\tkinter\__init__.py中)
def configure(self, cnf=None, **kw):
"""Configure resources of a widget.
The values for resources are specified as keyword
arguments. To get an overview about
the allowed keyword arguments call the method keys.
"""
return self._configure('configure', cnf, kw)
config = configure所以他们是一样的
https://stackoverflow.com/questions/63280876
复制相似问题