Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()
like image 311
Sats17 Avatar asked Dec 18 '22 09:12

Sats17


1 Answers

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.

like image 71
mgul Avatar answered Apr 21 '23 02:04

mgul