Mundo em Python

Máquina de Café(usando Tkinter)

import tkinter as tk
from functools import partial tempVal = "espresso"

def store_temp(sel_temp):
global tempVal
tempVal = sel_temp MENU = {
"Espresso": {
"ingredientes": {
"água": 50,
"café": 18,
},
"custo": 1.5,
},
"Latte": {
"ingredientes": {
"água": 200,
"leite": 150,
"café": 24,
},
"custo": 2.5,
},
"Cappuccino": {
"ingredientes": {
"água": 250,
"leite": 100,
"café": 24,
},
"custo": 3.0,
}
} recursos = {
"água": 300,
"leite": 200,
"café": 100,
} def deduzir_recursos(escolha_bebida):
receita_bebida = MENU[escolha_bebida]['ingredientes']
for ingrediente in receita_bebida:
recursos[ingrediente] -= receita_bebida[ingrediente] def verificar_recursos(escolha_bebida):
recursos_suficientes = True
receita_bebida = MENU[escolha_bebida]['ingredientes']
for ingrediente in receita_bebida:
if receita_bebida[ingrediente] > recursos[ingrediente]:
recursos_suficientes = False
return recursos_suficientes def processar_transação(bebida, moedas):
global dinheiro
sucesso = False
custo_bebida = MENU[bebida]['custo']
if custo_bebida > moedas:
return "Desculpe, não é suficiente dinheiro. Dinheiro devolvido."
elif custo_bebida <= moedas:
sucesso = True
troco = round(moedas - custo_bebida, 2)
dinheiro += custo_bebida
return f"Aqui está {troco}€ de troco. Aqui está o seu {bebida}, Aproveite! "

def call_convert(rlabel1, inputn):
tem = float(inputn.get())
if tempVal in ['Espresso', 'Latte', 'Cappuccino']:
if not verificar_recursos(tempVal):
mensagem = "Desculpe, não há ingredientes suficientes."
else:
mensagem = processar_transação(tempVal, tem)
rlabel1.config(text=mensagem)
elif tempVal == 'Desligar':
rlabel1.config(text="A máquina agora será desligada.")
elif tempVal == 'Relatório':
rlabel1.config(text=f"Água: {recursos['água']}ml\nLeite: {recursos['leite']}ml\nCafé: {recursos['café']}g\nDinheiro: R${dinheiro}") root = tk.Tk()
root.geometry('400x150+100+200')
root.title('Máquina de Café')
root.configure(background='#09A3BA')
root.resizable(width=False, height=False)
root.grid_columnconfigure(1, weight=1)
root.grid_rowconfigure(0, weight=1) numberInput = tk.StringVar()
var = tk.StringVar() input_label = tk.Label(root, text="Dinheiro Colocado", background='#09A3BA', foreground="#FFFFFF",font=("Arial","12","bold"))
input_entry = tk.Entry(root, textvariable=numberInput)
input_label.place(relx=0.05,rely=0.05)
input_entry.place(relx=0.5,rely=0.05) result_label1 = tk.Label(root, background='#09A3BA', foreground="#FFFFFF")
result_label1.grid(row=3, columnspan=4) dropDownList = ["Espresso", "Latte", "Cappuccino","Desligar","Relatório"]
dropdown = tk.OptionMenu(root, var, *dropDownList, command=store_temp)
var.set(dropDownList[0])
dropdown.place(relx=0.35,rely=0.3, relwidth=0.35)
dropdown.config(background='#09A3BA', foreground="#FFFFFF")
dropdown["menu"].config(background='#09A3BA', foreground="#FFFFFF")
call_convert = partial(call_convert, result_label1, numberInput)
result_button = tk.Button(root, text="Convert", command=call_convert, background='#09A3BA', foreground="#FFFFFF")
result_button.place(relx=0.5,rely=0.6)
dinheiro = 0
root.mainloop()
0