Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import*
- def dpl_haut():
- global carré
- coord[1] -= 10
- Plan.delete(carré)
- carré = Plan.create_rectangle(coord[0], coord[1], coord[0] + 15, coord[1] + 15, fill ="black")
- def dpl_bas():
- global carré
- coord[1] += 10
- Plan.delete(carré)
- carré = Plan.create_rectangle(coord[0], coord[1], coord[0] + 15, coord[1] + 15, fill ="black")
- def dpl_droite():
- global carré
- coord[0] += 10
- Plan.delete(carré)
- carré = Plan.create_rectangle(coord[0], coord[1], coord[0] + 15, coord[1] + 15, fill ="black")
- def dpl_gauche():
- global carré
- coord[0] -= 10
- Plan.delete(carré)
- carré = Plan.create_rectangle(coord[0], coord[1], coord[0] + 15, coord[1] + 15, fill ="black")
- if coord[0] < 0:
- Plan.delete(carré)
- carré = Plan.create_rectangle(position1, position2, position1 + 15, position2 + 15, fill ="black")
- # Paramètres de la fenêtre
- window = Tk()
- window.title("Jeu cool")
- window.geometry("500x500")
- position1 = 165
- position2 = 100
- coord = [position1, position2]
- # Paramètres du plan; création des contours avec les "Plan.create_line"; création du carré à déplacer "Plan.create_rectangle"
- Plan = Canvas(window, bg = "white", height ="240", width ="349")
- Plan.place(x = 100 , y = 60)
- Ligne_hor1 = Plan.create_line(2, 0, 2, 240)
- Ligne_hor2 = Plan.create_line(350, 0, 350, 240)
- Ligne_vert1 = Plan.create_line(2, 240, 351, 240)
- Ligne_vert2 = Plan.create_line(2, 2, 351, 2)
- carré = Plan.create_rectangle(position1, position2, position1 + 15, position2 + 15, fill ="black")
- # Paramètres dédiés aux boutons
- left_B = Button(window, text = "Gauche", width = "6", command = dpl_gauche)
- left_B.place(x = 278 , y = 400)
- right_B = Button(window, text = "Droite", width = "6", command = dpl_droite)
- right_B.place(x = 382 , y = 400)
- down_B = Button(window, text = "Bas", width = "6", command = dpl_bas)
- down_B.place(x = 330 , y = 430)
- up_B = Button(window, text = "Haut", width = "6", command = dpl_haut)
- up_B.place(x = 330 , y = 370)
- # Taux de rafraîchissement de la fenêtre
- window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement