Mundo em Python

Jogo das Lâmpadas (usando Tkinter)

from tkinter import *
from PIL import Image, ImageTk
root = Tk()
root.title("Acender Lâmpada")
root.configure(background="#f0f3f5")
root.geometry("500x260")
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="Acenda as lâmpadas",
font=("Arial","15"),bg="#3fb5a3")
texto1.place(relx=0.25,rely=0.15)
# Imagens
img1=ImageTk.PhotoImage(Image.open("0.png"))
img2=ImageTk.PhotoImage(Image.open("1.png"))
def fbutao3():
if (butao3['text'] == '0'):
butao3['text'] = '1'
butao3['bg'] = '#FFFF00'
l_1.config(image=img2)
else:
butao3['text'] = '0'
butao3['bg'] = 'white'
l_1.config(image=img1)
def fbutao1():
if (butao1['text'] == '0'):
butao1['text'] = '1'
butao1['bg'] = '#FFFF00'
l_3.config(image=img2)
else:
butao1['text'] = '0'
butao1['bg'] = 'white'
l_3.config(image=img1)
def fbutao5():
if (butao5['text'] == '0'):
butao5['text'] = '1'
butao5['bg'] = '#FFFF00'
l_2.config(image=img2)
else:
butao5['text'] = '0'
butao5['bg'] = 'white'
l_2.config(image=img1) def fbutao2():
if (butao2['text'] == '0'):
butao2['text'] = '1'
butao2['bg'] = 'white'
else:
butao2['text'] = '0'
butao2['bg'] = 'white'

def fbutao4():
if (butao4['text'] == '0'):
butao4['text'] = '1'
butao4['bg'] = 'white'
else:
butao4['text'] = '0'
butao4['bg'] = 'white'

l_1 = Label(frame_meio,bg="#403d3d")
l_1.place(relx=0.05,rely=0.2)
l_1.config(image=img1)
l_2 = Label(frame_meio,bg="#403d3d")
l_2.place(relx=0.23,rely=0.2)
l_2.config(image=img1)
l_3 = Label(frame_meio,bg="#403d3d")
l_3.place(relx=0.43,rely=0.2)
l_3.config(image=img1)
# Butão
butao1 = Button(frame_meio, text="0", bd=2,
bg='white', fg='black',state='normal',command=fbutao1)
butao1.place(relx=0.7, rely=0.05, relwidth=0.25, relheight=0.1) butao2 = Button(frame_meio,text="0", bd=2,
bg='white', fg='black', font=('verdana', 8, 'bold'),state='normal'
,command=fbutao2) butao2.place(relx=0.7, rely=0.2, relwidth=0.25, relheight=0.1)
butao3 = Button(frame_meio,text="0", bd=2,
bg='white', fg='black', font=('verdana', 8, 'bold'),state='normal'
,command=fbutao3)
butao3.place(relx=0.7, rely=0.35, relwidth=0.25, relheight=0.1)
butao4 = Button(frame_meio,text="0", bd=2,
bg='white', fg='black', font=('verdana', 8, 'bold'),state='normal',
command=fbutao4)
butao4.place(relx=0.7, rely=0.5, relwidth=0.25, relheight=0.1)
butao5 = Button(frame_meio,text="0", bd=2,
bg='white', fg='black', font=('verdana', 8, 'bold'),state='normal',
command=fbutao5)
butao5.place(relx=0.7, rely=0.63, relwidth=0.25, relheight=0.1)
root.mainloop()
0