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()
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With