Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background color for Tk in Python

Tags:

python

tkinter

tk

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) 
like image 753
olofom Avatar asked Apr 30 '10 13:04

olofom


People also ask

How do I change the background color in Python Tk?

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.

What is BG in tkinter?

background or bg is one attribute in most of Tkinter widgets, and could be used to set the background color directly.

What we use to change the background color any widget in Python?

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.


1 Answers

root.configure(background='black') 

or more generally

<widget>.configure(background='black') 
like image 119
msw Avatar answered Sep 23 '22 18:09

msw