Comment définir la couleur du fond de panier de Tkinter
-
La méthode
configure(background= )est utilisée pour définir la couleur de fond des widgets et des fenêtres de Tkinter -
L’attribut
bgoubackground - Code couleur Tkinter
La méthode de classe de widget Tkinter configure et l’attribut bg ou backgroud peuvent être utilisés pour définir la couleur de fond du widget/fenêtre Tkinter.
La méthode configure(background= ) est utilisée pour définir la couleur de fond des widgets et des fenêtres de Tkinter
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()
Tenez,
app.configure(bg='red') configure la couleur de fond de app pour qu’elle soit red. Vous pouvez aussi utiliser background au lieu de bg.
app.configure(background='red')

L’attribut bg ou background
L’attribut background ou bg est présent dans la plupart des widgets Tkinter, et peut être utilisé pour définir directement la couleur de fond.
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()

Code couleur Tkinter
Vous pouvez spécifier la couleur avec les noms connus comme red, blue ou green comme montré ci-dessus, et vous pouvez aussi la spécifier via RGB comme des codes de couleur hexagonaux en HTML, par exemple, #49A ou #0059b3.
try:
import Tkinter as tk
except:
import tkinter as tk
app = tk.Tk()
app.title("bg attribute")
app.geometry("300x200")
app["bg"] = "#0059b3"
app.mainloop()

try:
import Tkinter as tk
except:
import tkinter as tk
app = tk.Tk()
app.title("bg attribute")
app.geometry("300x200")
app["bg"] = "#49A"
app.mainloop()

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 Facebook