HOWTO · Tkinter
Come impostare il colore di sfondo di Tkinter
Questo tutorial introduce come impostare il colore di sfondo di Tkinter
In questa pagina
Il metodo della classe del widget Tkinter configure e l’attributo bg o backgroud potrebbero essere usati per impostare il colore di sfondo del widget/finestra Tkinter.
Metodo 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()
Qui,
app.configure(bg='red') configura il colore di sfondo di app come red. Si può anche usare background invece di bg.
app.configure(background="red")
Attributo bg o background
background o bg è un attributo nella maggior parte dei widget di Tkinter, e potrebbe essere usato per impostare direttamente il colore di sfondo.
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()
Codice colore Tkinter
Si può specificare il colore con i nomi noti come red, blue o green come mostrato sopra, e si può anche specificare tramite RGB come codici colore esadecimali in HTML, ad esempio, #49A o #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()