如何设置 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()
多动手,多练习,多理解,加油!!!
觉得不错的话,记得帮我 @小象点个赞哟,祝大家都能学有所获!
发布于 2022-03-29 16:03