Mundo em Python

Interruptor (usando Tkinter)

from tkinter import *
from PIL import Image, ImageTk
root = Tk()
root.title("Acender e Apagar a Luz")
root.configure(background="#f0f3f5")
root.geometry("500x400")
root.resizable(False,False)
frame_cima = Frame(root, bd=4, bg="#3fb5a3"
, highlightbackground='#759fe6', highlightthickness=2)
frame_cima.place(relx=0.02, rely=0.02, relwidth=0.96, relheight=0.2) frame_meio = Frame(root, bd=4, bg="#403d3d"
, highlightbackground='#759fe6', highlightthickness=2)
frame_meio.place(relx=0.02, rely=0.2, relwidth=0.96, relheight=0.9)
# função para ligar a lâmpada

texto1 = Label(frame_cima,text="Interruptor",
font=("Arial","30","bold"),bg="#3fb5a3")
texto1.place(relx=0.3,rely=0.15)
# Imagens
img1=ImageTk.PhotoImage(Image.open("desligado.png"))
img2=ImageTk.PhotoImage(Image.open("ligado.png")) def fbutao1():
if (butao1['text'] == 'Desligado'):
butao1['text'] = 'Ligado'
butao1['bg'] = '#FFFF00'
l_1.config(image=img2)
else:
butao1['text'] = 'Desligado'
butao1['bg'] = 'white'
l_1.config(image=img1) l_1 = Label(frame_meio,bg="#403d3d")
l_1.place(relx=0.1,rely=0.2)
l_1.config(image=img1)
# Butão
butao1 = Button(frame_meio, text="Desligado", bd=2,
bg='white', fg='black',state='normal',command=fbutao1,font=("Arial","13","bold"))
butao1.place(relx=0.7, rely=0.4, relwidth=0.25, relheight=0.1) root.mainloop()
0