如何设置 Tkinter 背景色
Tkinter 控件类中的方法 configure
和属性 bg
或 backgroud
可用于设置 Tkinter 控件/窗口背景颜色。
configure(background= )
方法
try:
import Tkinter as tk
except:
import tkinter as tk
app = tk.Tk()
app.title("configure method")
app.geometry('300x200')
app.configure(bg='red')
app.mainloop()
这里,
app.configure(bg='red')
将 app
的颜色设置成 red
。你也可以用 background
来替代 bg
。
app.configure(background='red')
bg
或 background
属性
background
或 bg
是大多数 Tkinter 控件中的一个属性,可用于直接设置背景颜色。
try:
import Tkinter as tk
except:
import tkinter as tk
app = tk.Tk()
app.title("bg attribute")
app.geometry('300x200')
app['bg'] = 'blue'
app.mainloop()
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布,任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站。本站所有源码与软件均为原作者提供,仅供学习和研究使用。如您对本站的相关版权有任何异议,或者认为侵犯了您的合法权益,请及时通知我们处理。