Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. from tkinter import*
  2.  
  3. def dpl_haut():
  4. global carré
  5. coord[1] -= 10
  6. Plan.delete(carré)
  7. carré = Plan.create_rectangle(coord[0], coord[1], coord[0] + 15, coord[1] + 15, fill ="black")
  8.  
  9. def dpl_bas():
  10. global carré
  11. coord[1] += 10
  12. Plan.delete(carré)
  13. carré = Plan.create_rectangle(coord[0], coord[1], coord[0] + 15, coord[1] + 15, fill ="black")
  14.  
  15. def dpl_droite():
  16. global carré
  17. coord[0] += 10
  18. Plan.delete(carré)
  19. carré = Plan.create_rectangle(coord[0], coord[1], coord[0] + 15, coord[1] + 15, fill ="black")
  20.  
  21. def dpl_gauche():
  22. global carré
  23. coord[0] -= 10
  24. Plan.delete(carré)
  25. carré = Plan.create_rectangle(coord[0], coord[1], coord[0] + 15, coord[1] + 15, fill ="black")
  26. if coord[0] < 0:
  27. Plan.delete(carré)
  28. carré = Plan.create_rectangle(position1, position2, position1 + 15, position2 + 15, fill ="black")
  29.  
  30. # Paramètres de la fenêtre
  31. window = Tk()
  32. window.title("Jeu cool")
  33. window.geometry("500x500")
  34.  
  35.  
  36.  
  37.  
  38. position1 = 165
  39. position2 = 100
  40.  
  41. coord = [position1, position2]
  42.  
  43.  
  44. # Paramètres du plan; création des contours avec les "Plan.create_line"; création du carré à déplacer "Plan.create_rectangle"
  45. Plan = Canvas(window, bg = "white", height ="240", width ="349")
  46. Plan.place(x = 100 , y = 60)
  47. Ligne_hor1 = Plan.create_line(2, 0, 2, 240)
  48. Ligne_hor2 = Plan.create_line(350, 0, 350, 240)
  49. Ligne_vert1 = Plan.create_line(2, 240, 351, 240)
  50. Ligne_vert2 = Plan.create_line(2, 2, 351, 2)
  51. carré = Plan.create_rectangle(position1, position2, position1 + 15, position2 + 15, fill ="black")
  52.  
  53.  
  54. # Paramètres dédiés aux boutons
  55. left_B = Button(window, text = "Gauche", width = "6", command = dpl_gauche)
  56. left_B.place(x = 278 , y = 400)
  57. right_B = Button(window, text = "Droite", width = "6", command = dpl_droite)
  58. right_B.place(x = 382 , y = 400)
  59. down_B = Button(window, text = "Bas", width = "6", command = dpl_bas)
  60. down_B.place(x = 330 , y = 430)
  61. up_B = Button(window, text = "Haut", width = "6", command = dpl_haut)
  62. up_B.place(x = 330 , y = 370)
  63.  
  64. # Taux de rafraîchissement de la fenêtre
  65. window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement