Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #!/usr/bin/python3
  2. # -*- coding: utf-8 -*-
  3. from tkinter import *
  4. from random import randrange
  5.  
  6. #definition de a:
  7. a = 0
  8. a = int(a)
  9. #definition des fonctions gestionnaires déveénements:
  10. def drawline():
  11. "tracé d'une ligne de le canevas can1"
  12. global x1,y1,x2,y2
  13. can1.create_oval(x1,y1,x2,y2, width=2, fill=coul)
  14.  
  15. #modification des coordonnées pour la ligne suivante:
  16. x1, x2 = x1+150, x2+150
  17. a = a+1
  18. if a == 5:
  19. x1, y1, x2, y2 = x1-600, y1+150, x2-600, y2+150
  20. def changecolor():
  21. "changement aléatoire de la couleur du tracé"
  22. global coul
  23. pal=['purple', 'cyan', 'maroon', 'green', 'red', 'blue', 'orange', 'yellow']
  24. c = randrange(8) # ==> génère un nombre aléatoire de 0 à 7
  25. coul = pal[c]
  26.  
  27. # prormame pricnipal
  28.  
  29. #les variables suivantes seront utilisées de manière globale:
  30. x1, y1, x2, y2 = 110, 10, 10, 100 #coordonnées
  31. coul ='darkgreen' #couleur de la ligne
  32.  
  33. # création du widget pricniaple ("maitre")
  34. fen1 = Tk()
  35. # création des widgets esclaves:
  36. can1 = Canvas(fen1, bg='yellow', height=650, width=500)
  37. can1.pack(side=LEFT)
  38. bou1 = Button(fen1, text='quitter',command=fen1.quit)
  39. bou1.pack(side=BOTTOM)
  40. bou2 = Button(fen1,text='tracer une ligne', command=drawline)
  41. bou2.pack()
  42. bou3 = Button(fen1, text='autre couleur',command=changecolor)
  43. bou3.pack()
  44. bou4 = Button(fen1, text='bonjour',command=lambda:print("bonjour"))
  45. bou4.pack()
  46.  
  47. fen1.mainloop()
  48. fen1.destroy()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement