-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathetch-a-sketch.py
More file actions
40 lines (31 loc) · 1.1 KB
/
etch-a-sketch.py
File metadata and controls
40 lines (31 loc) · 1.1 KB
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
import turtle
class sketch_book:
def __init__(self) -> None:
self.tim=turtle.Turtle()
self.screen=turtle.Screen()
color=self.screen.textinput("color","choose the color of pen ")
size=self.screen.textinput("size","choose the size of pen (in range 1 to 10)")
self.tim.color(color)
self.tim.pensize(size)
self.listen()
self.screen.mainloop()
def movefd(self):
self.tim.fd(30)
def movebk(self):
self.tim.bk(30)
def left(self):
self.tim.left(10)
def right(self):
self.tim.right(10)
def clear(self):
self.tim.clear()
def listen(self):
self.screen.listen()
self.screen.onkeypress(key="Up",fun=self.movefd)
self.screen.onkeypress(key="Down",fun=self.movebk)
self.screen.onkeypress(key="Left",fun=self.left)
self.screen.onkeypress(key="Right",fun=self.right)
self.screen.onkeypress(key="c",fun=self.clear)
self.tim.ondrag(self.tim.goto)
if __name__=="__main__":
game1=sketch_book()