Image On Off switch

Tkinter Buttons Image

Button with On image
Button with Off image

Here are two images used. ( Right click and save images in PNG format )

On off switch image OFF position On off switch image ON position

Tkinter button with ON OFF images switch to configure window background colour for night mode

We can use this as Night Mode switch and change the window background colour. Here the variables are set to two different colours, this can be changed to match your requirements.
import tkinter as tk
my_w = tk.Tk() 
my_w.geometry("400x300")  # Size of the window
colour_night='lightgreen' # Change the night colour 
colour_day='blue'         # change the day colour 
my_w.configure(background=colour_day) # default background of window
my_img_on = tk.PhotoImage(file = "D:\\testing\\on-off-on.png")
my_img_off = tk.PhotoImage(file = "D:\\testing\\on-off-off.png") 
def my_upd():
my_w.mainloop()  # Keep the window open

Resizing image using PIL Upload and display image file Colorchooser
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2022 All rights reserved worldwide Privacy Policy Disclaimer