ยปCore Development>Code coverage>Demo/tkinter/guido/paint.py

Python code coverage for Demo/tkinter/guido/paint.py

#countcontent
1n/a""""Paint program by Dave Michell.
2n/a
3n/aSubject: tkinter "paint" example
4n/aFrom: Dave Mitchell <davem@magnet.com>
5n/aTo: python-list@cwi.nl
6n/aDate: Fri, 23 Jan 1998 12:18:05 -0500 (EST)
7n/a
8n/a Not too long ago (last week maybe?) someone posted a request
9n/afor an example of a paint program using Tkinter. Try as I might
10n/aI can't seem to find it in the archive, so i'll just post mine
11n/ahere and hope that the person who requested it sees this!
12n/a
13n/a All this does is put up a canvas and draw a smooth black line
14n/awhenever you have the mouse button down, but hopefully it will
15n/abe enough to start with.. It would be easy enough to add some
16n/aoptions like other shapes or colors...
17n/a
18n/a yours,
19n/a dave mitchell
20n/a davem@magnet.com
21n/a"""
22n/a
23n/afrom tkinter import *
24n/a
25n/a"""paint.py: not exactly a paint program.. just a smooth line drawing demo."""
26n/a
27n/ab1 = "up"
28n/axold, yold = None, None
29n/a
30n/adef main():
31n/a root = Tk()
32n/a drawing_area = Canvas(root)
33n/a drawing_area.pack()
34n/a drawing_area.bind("<Motion>", motion)
35n/a drawing_area.bind("<ButtonPress-1>", b1down)
36n/a drawing_area.bind("<ButtonRelease-1>", b1up)
37n/a root.mainloop()
38n/a
39n/adef b1down(event):
40n/a global b1
41n/a b1 = "down" # you only want to draw when the button is down
42n/a # because "Motion" events happen -all the time-
43n/a
44n/adef b1up(event):
45n/a global b1, xold, yold
46n/a b1 = "up"
47n/a xold = None # reset the line when you let go of the button
48n/a yold = None
49n/a
50n/adef motion(event):
51n/a if b1 == "down":
52n/a global xold, yold
53n/a if xold is not None and yold is not None:
54n/a event.widget.create_line(xold,yold,event.x,event.y,smooth=TRUE)
55n/a # here's where you draw it. smooth. neat.
56n/a xold = event.x
57n/a yold = event.y
58n/a
59n/aif __name__ == "__main__":
60n/a main()