Tkinter の背景色を設定する
Jinku Hu
2022年12月21日
2019年12月7日
Tkinter
Tkinter Background

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
に設定します。bg
の代わりに background
を使ってもいいです。
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()
Author: Jinku Hu
Founder of DelftStack.com. Jinku has worked in the robotics and automotive industries for over 8 years. He sharpened his coding skills when he needed to do the automatic testing, data collection from remote servers and report creation from the endurance test. He is from an electrical/electronics engineering background but has expanded his interest to embedded electronics, embedded programming and front-/back-end programming.
LinkedIn