【问题标题】:Utility of config() in python tkinterpython tkinter 中 config() 的实用程序
【发布时间】:2017-02-28 14:17:36
【问题描述】:

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

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()

【问题讨论】:

  • 你有没有做过基础研究,比如阅读一些文档?

标签: python-2.7 python-3.x tkinter


【解决方案1】:

config 用于在初始化后访问对象的属性。例如,在这里,您定义

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

但是你想设置它的text属性,所以你使用config

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

这样您就可以设置文本,并在运行时对其进行修改。

【讨论】:

  • config和configure一样吗?
猜你喜欢
  • 1970-01-01
  • 2021-03-04
  • 2016-05-04
  • 2013-05-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-21
相关资源
最近更新 更多