# Überführungfunktion und Ausgabefunktion an diese Stelle kopieren


from tkinter import *

tkFenster = Tk()
tkFenster.title('Kunstautomat')
tkFenster.geometry('400x400')

aktuellerZustand = "0"

def updateCanvas(zustand, ausgabe):
    print('aktueller Zustand:', zustand, ' letzte Ausgabe:', ausgabe)
    if ausgabe == 'Ware':
        zeigeKunstwerk()
        versteckeMuenze1Euro()
        versteckeMuenze2Euro()
    elif ausgabe == '1€':
        versteckeKunstwerk()
        zeigeMuenze1Euro()
        versteckeMuenze2Euro()
    elif ausgabe == '2€':
        versteckeKunstwerk()
        versteckeMuenze1Euro()
        zeigeMuenze2Euro()
    elif ausgabe == 'nichts':
        versteckeKunstwerk()
        versteckeMuenze1Euro()
        versteckeMuenze2Euro()
        
def versteckeKunstwerk():
    global canvas
    canvas.itemconfigure(kunstwerkId, state='hidden')

def zeigeKunstwerk():
    global canvas
    canvas.itemconfigure(kunstwerkId, state='normal')

def versteckeMuenze1Euro():
    global canvas
    canvas.itemconfigure(muenze1EuroIdOval, state='hidden')
    canvas.itemconfigure(muenze1EuroIdText, state='hidden')
    
def zeigeMuenze1Euro():
    global canvas
    canvas.itemconfigure(muenze1EuroIdOval, state='normal')
    canvas.itemconfigure(muenze1EuroIdText, state='normal')

def versteckeMuenze2Euro():
    global canvas
    canvas.itemconfigure(muenze2EuroIdOval, state='hidden')
    canvas.itemconfigure(muenze2EuroIdText, state='hidden')
    
def zeigeMuenze2Euro():
    global canvas
    canvas.itemconfigure(muenze2EuroIdOval, state='normal')
    canvas.itemconfigure(muenze2EuroIdText, state='normal')
    
def handle1EuroClicked():
    global aktuellerZustand
    ausgabe = ausgabefunktion(aktuellerZustand, '1€')
    aktuellerZustand = ueberfuehrungsfunktion(aktuellerZustand, '1€')
    versteckeKunstwerk()
    updateCanvas(aktuellerZustand, ausgabe)
    
def handleWareClicked():
    global aktuellerZustand
    ausgabe = ausgabefunktion(aktuellerZustand, 'Ware')
    aktuellerZustand = ueberfuehrungsfunktion(aktuellerZustand, 'Ware')
    updateCanvas(aktuellerZustand, ausgabe)

def handleGeldClicked():
    global aktuellerZustand
    ausgabe = ausgabefunktion(aktuellerZustand, 'Geld')    
    aktuellerZustand = ueberfuehrungsfunktion(aktuellerZustand, 'Geld')
    updateCanvas(aktuellerZustand, ausgabe)
    
canvas = Canvas(master=tkFenster, bg='white')
canvas.place(x=20, y=20, width=200, height=300)

# Gehäuse
canvas.create_rectangle(20, 20, 180, 280, fill='sky blue')

canvas.create_text(100,50, text="Kunstautomat", font=('Helvetica', '16'))

# Schlitz für Münzeinwurf
canvas.create_rectangle(140,80,150,110, fill='black')

# Ausgabe Kunstwerke
canvas.create_rectangle(40,220,110,250, fill='grey')

# Ausgabe Geld
canvas.create_rectangle(130,220,160,250, fill='grey')

# 1 Euro Münze
muenze1EuroIdOval = canvas.create_oval(120, 225, 150, 255, fill='yellow')
muenze1EuroIdText = canvas.create_text(135, 240, text="1€")

# 2 Euro Münze
muenze2EuroIdOval = canvas.create_oval(140, 225, 170, 255, fill='yellow')
muenze2EuroIdText = canvas.create_text(155, 240, text="2€")

# Kunstwerk
kunstwerkId = canvas.create_rectangle(45,230,105,270, fill='red')

button1Euro = Button(master=tkFenster, text="1€ einwerfen", command=handle1EuroClicked)
button1Euro.place(x=280, y=50, width=100, height=40)

buttonWare = Button(master=tkFenster, text="Ware", command=handleWareClicked)
buttonWare.place(x=60, y=180, width=50, height=40)

buttonGeld = Button(master=tkFenster, text="Geld", command=handleGeldClicked)
buttonGeld.place(x=130, y=180, width=50, height=40)

versteckeKunstwerk()
versteckeMuenze1Euro()
versteckeMuenze2Euro()

tkFenster.mainloop()