如何設定 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()