python tkinter中config()的实用程序

Sat*_*s17 2 tkinter python-2.7 python-3.x

我有这个python脚本,config()在python tkinter模块中有什么用?

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()
Run Code Online (Sandbox Code Playgroud)

mgu*_*gul 8

config用于在初始化后访问对象的属性.例如,在这里,你定义l = Label(root, bg="ivory", fg="darkgreen"),但是你想要设置他的text属性,所以你使用config:
l.config(text="Correct answer!")
这样你就可以设置文本,并在一段时间内修改它.