Sats17
Sats17

Reputation: 95

Utility of config() in python tkinter

I have this python script, what is the use of config() in the python tkinter module?

from tkinter import *   
root=Tk()
def sel():
   s=v.get()
   if s=="m":
       l.config(text="CORRECT ANSWER!!!")
   else:
       l.config(text="WRONG ANSWER")
v=StringVar()
a=Label(root,text="Delhi is the capital of India.",bg="wheat",fg="blue")
a.pack()
r1=Radiobutton(root,text="True",variable=v,value="m",command=sel)
r1.pack(anchor=W)
r2=Radiobutton(root,text="False",variable=v,value="n",command=sel)
r2.pack(anchor=W)
l=Label(root,bg="ivory",fg="darkgreen")
l.pack()
root.mainloop()

Upvotes: 4

Views: 38965

Answers (1)

mgul
mgul

Reputation: 742

config is used to access an object's attributes after its initialisation. For example, here, you define

l = Label(root, bg="ivory", fg="darkgreen")

but then you want to set its text attribute, so you use config:

l.config(text="Correct answer!")

That way you can set the text, and modify it during runtime.

Upvotes: 11

Related Questions