What is the difference between .config() and .configure() in Tkinter
Question:
Im a beginner in python. Recently I finished the basics and now I’m trying to make some GUI applications. I have found many cases where we use config() and configure(). But what is the difference between config() and configure()?
I mean, in what cases config() should be used and in what cases should configure() be used. i have a small portion of my code here.
Code where Configure is used:
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)
Code where config is used:
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)
It would of great help if someone would clear this doubt.
Answers:
Both are exactly the same, the only difference is, the difference in the name, I would just reccomend using .config()
just to save a few typing characters 😉
Config or configure brings the same results.
The best way to find out the differences is to see the source code
of tkinter’s __init__.py
(in my example it is in Thonny – ThonnyLibtkinter__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
So they are the same
Im a beginner in python. Recently I finished the basics and now I’m trying to make some GUI applications. I have found many cases where we use config() and configure(). But what is the difference between config() and configure()?
I mean, in what cases config() should be used and in what cases should configure() be used. i have a small portion of my code here.
Code where Configure is used:
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)
Code where config is used:
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)
It would of great help if someone would clear this doubt.
Both are exactly the same, the only difference is, the difference in the name, I would just reccomend using .config()
just to save a few typing characters 😉
Config or configure brings the same results.
The best way to find out the differences is to see the source code
of tkinter’s __init__.py
(in my example it is in Thonny – ThonnyLibtkinter__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
So they are the same