I'm writing a slideshow program with Tkinter, but I don't know how to change the background color to black instead of the standard light gray. How can this be done?
import os, sys import Tkinter import Image, ImageTk import time root = Tkinter.Tk() w, h = root.winfo_screenwidth(), root.winfo_screenheight() root.overrideredirect(1) root.geometry("%dx%d+0+0" % (w, h)) root.focus_set() root.bind("<Escape>", lambda e: e.widget.quit()) image = Image.open(image_path+f) tkpi = ImageTk.PhotoImage(image) label_image = Tkinter.Label(root, image=tkpi) label_image.place(x=0,y=0,width=w,height=h) root.mainloop(0)
There are two ways to change the background color of a window in Tkinter: By using the configure(bg=”) method of the tkinter.Tk class. Set the bg property of tkinter.Tk directly.
background or bg is one attribute in most of Tkinter widgets, and could be used to set the background color directly.
We can customize the tkinter widgets using the tkinter. ttk module. Tkinter. ttk module is used for styling the tkinter widgets such as setting the background color, foreground color, activating the buttons, adding images to labels, justifying the height and width of widgets, etc.
root.configure(background='black')
or more generally
<widget>.configure(background='black')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With