Как сделать вызов функции по клавише, например: При нажатии на "Space" удаляется текст и два изображения в окне.
Вот код:
Вот код:
Python:
from tkinter import *
from tkinter import messagebox
def on_closing():
if messagebox.askokcancel("Выход из игры", "Хотите выйти из игры?"):
tk.destroy()
tk = Tk()
tk.title("Breath of Two")
tk.resizable(0, 0)
tk.wm_attributes("-topmost", 2)
tk.protocol("WM_DELETE_WINDOW", on_closing)
canvas = Canvas(tk, width=1024, height=800, bd=0, highlightthickness=0)
canvas.pack()
our_image = PhotoImage(file="photo/menu.png")
our_image = our_image.subsample(-1, 1)
our_lable = Label(tk)
our_lable.image = our_image
our_lable['image'] = our_lable.image
our_lable.place(x=5, y=15)
def new_window_playzone1():
new_window_playzone1 = Toplevel(tk)
new_window_playzone1.title("Breath of Two")
new_window_playzone1.wm_attributes("-topmost", 1)
new_window_playzone1.resizable(0, 0)
canvas_playzone1 = Canvas(new_window_playzone1, width=1700, height=900, bg="#555", highlightthickness=0)
canvas_playzone1.pack()
our_image2 = PhotoImage(file="photo/tolpa-zombi.png")
our_lable2 = Label(new_window_playzone1)
our_lable2.image = our_image2
our_lable2['image'] = our_lable2.image
our_lable2.place(x=1, y=1)
lbl1 = Label(new_window_playzone1, text=Вступление, font=("Calibri", 25, "bold"), bg="#FFA500")
lbl1.place(x=5, y=500)
our_image1 = PhotoImage(file="photo/virused.png")
our_image1 = our_image1.subsample(1, 1)
our_lable1 = Label(new_window_playzone1)
our_lable1.image = our_image1
our_lable1['image'] = our_lable1.image
our_lable1.place(x=10, y=26)
our_image3 = PhotoImage(file="photo/scientist.png")
our_image3 = our_image3.subsample(1, 1)
our_lable3 = Label(new_window_playzone1)
our_lable3.image = our_image3
our_lable3['image'] = our_lable3.image
our_lable3.place(x=870, y=26)
def destroy_playzone1(): #Функция которую я хочу активировать при нажатии на "Space"
our_lable1.place_forget()
our_lable3.place_forget()
lbl1.place_forget()
b1 = Button(tk, text="Играть", command=new_window_playzone1, font=("Arial", 18), bg="#555", fg="#ccc")
b1.place(x=785, y=260, width=200, height=70)
tk.mainloop()