Advertisement
Guest User

Untitled

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