Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- # -*- coding: utf-8 -*-
- from tkinter import *
- from random import randrange
- #definition de a:
- a = 0
- a = int(a)
- #definition des fonctions gestionnaires déveénements:
- def drawline():
- "tracé d'une ligne de le canevas can1"
- global x1,y1,x2,y2
- can1.create_oval(x1,y1,x2,y2, width=2, fill=coul)
- #modification des coordonnées pour la ligne suivante:
- x1, x2 = x1+150, x2+150
- a = a+1
- if a == 5:
- x1, y1, x2, y2 = x1-600, y1+150, x2-600, y2+150
- def changecolor():
- "changement aléatoire de la couleur du tracé"
- global coul
- pal=['purple', 'cyan', 'maroon', 'green', 'red', 'blue', 'orange', 'yellow']
- c = randrange(8) # ==> génère un nombre aléatoire de 0 à 7
- coul = pal[c]
- # prormame pricnipal
- #les variables suivantes seront utilisées de manière globale:
- x1, y1, x2, y2 = 110, 10, 10, 100 #coordonnées
- coul ='darkgreen' #couleur de la ligne
- # création du widget pricniaple ("maitre")
- fen1 = Tk()
- # création des widgets esclaves:
- can1 = Canvas(fen1, bg='yellow', height=650, width=500)
- can1.pack(side=LEFT)
- bou1 = Button(fen1, text='quitter',command=fen1.quit)
- bou1.pack(side=BOTTOM)
- bou2 = Button(fen1,text='tracer une ligne', command=drawline)
- bou2.pack()
- bou3 = Button(fen1, text='autre couleur',command=changecolor)
- bou3.pack()
- bou4 = Button(fen1, text='bonjour',command=lambda:print("bonjour"))
- bou4.pack()
- fen1.mainloop()
- fen1.destroy()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement