1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
from tkinter import *
class dessin(Frame):
def __init__(self,parent=None):
Frame.__init__(self,parent)
self.pack(expand=YES, fill=BOTH)
self.var = IntVar()
self.fen = Frame(self, width=305, height=520, bd=1)
self.fen.pack(expand=YES, fill=BOTH)
self.fen1 = Frame(self.fen, bd=1, relief=SOLID)
self.fen1.pack(side=TOP, expand=YES, fill=X, pady=5, padx=5)
self.fen2 = Frame(self.fen, bd=1, relief=SOLID)
self.fen2.pack(side=TOP, expand=YES, fill=X, pady=5, padx=5)
self.can = Canvas(self.fen1, bg='white', width=300, height=250,
relief=SOLID)
self.can.pack(side=TOP, expand=YES, fill=BOTH)
self.can.bind("<Button-1>", self.clic)
self.can.bind("<ButtonRelease-1>", self.ligne)
## self.can.bind("<ButtonRelease>", self.oval)
self.but1 = Radiobutton(self.fen2, text='Ligne', variable=self.var,
value=1, command=self.ligne)
self.but1.pack(side=LEFT, fill=BOTH, expand=YES, padx=5, pady=5)
self.but2 = Radiobutton(self.fen2, text='Oval', variable=self.var,
value=2, command=self.oval)
self.but2.pack(side=LEFT, fill=BOTH, expand=YES, padx=5, pady=5)
def clic(self,last):
self.x, self.y = last.x, last.y
def ligne(self,last):
"""fonction gérant le tracé d'une courbe"""
self.can.create_line(self.x, self.y, last.x, last.y)
self.x, self.y = last.x, last.y
def oval(self,last):
"""fonction gérant le tracé d'un cercle"""
self.can.create_oval(self.x, self.y, last.x, last.y)
self.x, self.y = last.x, last.y
parent = Tk()
parent.title('dessin')
if __name__ == '__main__':
dessin().mainloop() |
Partager