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.

Asked By: user14030743

||

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 😉

Answered By: Aryan

Config or configure brings the same results.

Answered By: tan hongkiat

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

Answered By: Slava S.
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.