Tkinter 中的 .config() 和 .configure() 有什么区别?

6 python user-interface tkinter

我是 Python 初学者。最近,我完成了基础知识,现在我正在尝试制作一些 GUI 应用程序。我发现很多情况下我们使用config()configure()。但是config()和configure()有什么区别呢?

我的意思是,什么情况下应该config()用,什么情况下应该configure()用?我这里有一小部分代码。

使用Configure的代码:

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)
Run Code Online (Sandbox Code Playgroud)

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)
Run Code Online (Sandbox Code Playgroud)

如果有人能消除这个疑问,那将会有很大帮助。

Ham*_*ger 7

两者完全相同,唯一的区别是名称不同,我只是建议使用它.config()来节省一些打字字符;-)

  • 这绝对不是更快的速度。最多可能会快一皮秒。 (2认同)