Code: Alles auswählen
from tkinter import *
def delete_button(event):
global deletebutton
deletebutton = event.widget.pack_forget()
def Steinmine_bauen():
global abc
abc = abc
global Kreis
Kreis = w.create_oval(x1,y1,x2,y2, fill = "red")
b1.bind('<Button-1>', delete_button)
b2.bind('<Button-1>', delete_button)
b3.bind('<Button-1>', delete_button)
b4.bind('<Button-1>', delete_button)
b5.bind('<Button-1>', delete_button)
b1.pack()
b2.pack()
b3.pack()
b4.pack()
b5.pack()
master.mainloop()
def Goldmine_bauen():
global abc
abc = abc
global Kreis
Kreis = w.create_oval(x1,y1,x2,y2, fill = "red")
b1.bind('<Button-1>', delete_button)
b2.bind('<Button-1>', delete_button)
b3.bind('<Button-1>', delete_button)
b4.bind('<Button-1>', delete_button)
b5.bind('<Button-1>', delete_button)
b1.pack()
b2.pack()
b3.pack()
b4.pack()
b5.pack()
master.mainloop()
def Eisenerzmine_bauen():
global abc
abc = abc
global Kreis
Kreis = w.create_oval(x1,y1,x2,y2, fill = "red")
b1.bind('<Button-1>', delete_button)
b2.bind('<Button-1>', delete_button)
b3.bind('<Button-1>', delete_button)
b4.bind('<Button-1>', delete_button)
b5.bind('<Button-1>', delete_button)
b1.pack()
b2.pack()
b3.pack()
b4.pack()
b5.pack()
master.mainloop()
def Kohlemine_bauen():
global abc
abc = abc
global Kreis
Kreis = w.create_oval(x1,y1,x2,y2, fill = "red")
b1.bind('<Button-1>', delete_button)
b2.bind('<Button-1>', delete_button)
b3.bind('<Button-1>', delete_button)
b4.bind('<Button-1>', delete_button)
b5.bind('<Button-1>', delete_button)
b1.pack()
b2.pack()
b3.pack()
b4.pack()
b5.pack()
master.mainloop()
def Holzfäller_bauen():
global abc
abc = abc
global Kreis
Kreis = w.create_oval(x1,y1,x2,y2, fill = "red")
b1.bind('<Button-1>', delete_button)
b2.bind('<Button-1>', delete_button)
b3.bind('<Button-1>', delete_button)
b4.bind('<Button-1>', delete_button)
b5.bind('<Button-1>', delete_button)
b1.pack()
b2.pack()
b3.pack()
b4.pack()
b5.pack()
master.mainloop()
def Kreis_move_right():
w.delete(Kreis)
global x1
global x2
x1 = x1 + 5
x2 = x2 + 5
global Kreis
Kreis = w.create_oval(x1,y1,x2,y2, fill = "red")
def Kreis_move_left():
w.delete(Kreis)
global x1
global x2
x1 = x1 - 5
x2 = x2 - 5
global Kreis
Kreis = w.create_oval(x1,y1,x2,y2, fill = "red")
def Kreis_move_bot():
w.delete(Kreis)
global y1
global y2
y1 = y1 + 5
y2 = y2 + 5
global Kreis
Kreis = w.create_oval(x1,y1,x2,y2, fill = "red")
def Kreis_move_top():
w.delete(Kreis)
global y1
global y2
y1 = y1 - 5
y2 = y2 - 5
global Kreis
Kreis = w.create_oval(x1,y1,x2,y2, fill = "red")
abc = 0
x1 = 0
y1 = 0
x2 = 100
y2 = 100
master = Tk()
w = Canvas(master, width=1000, height=1000)
w.create_rectangle(0, 0, 1000,1000, fill="green")
w.pack(side = "left")
b1 = Button (text = "Steinmine", command = Steinmine_bauen)
b1.pack()
b2 = Button (text = "Goldmine", command = Goldmine_bauen)
b2.pack()
b3 = Button (text = "Eisenmine", command = Eisenerzmine_bauen)
b3.pack()
b4 = Button (text = "Kohlemine", command = Kohlemine_bauen)
b4.pack()
b5 = Button (text = "Holzfäller", command = Holzfäller_bauen)
b5.pack()
if abc == abc:
moveR = Button (text = "Rechts", command = Kreis_move_right)
moveR.pack(side = "right")
moveL = Button (text = "Links", command = Kreis_move_left)
moveL.pack(side = "right")
moveT = Button (text = "Oben", command = Kreis_move_top)
moveT.pack(side = "right")
moveB = Button (text = "Unten", command = Kreis_move_bot)
moveB.pack(side = "right")