-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtry.py
126 lines (81 loc) · 3.23 KB
/
try.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
from tkinter import *
current_x, current_y = 0,0
color = 'black'
def locate_xy(event):
global current_x, current_y
current_x, current_y = event.x, event.y
def addLine(event):
global current_x, current_y
canvas.create_line((current_x,current_y,event.x,event.y),fill = color)
current_x, current_y = event.x, event.y
def show_color(new_color):
global color
color = new_color
def new_canvas():
canvas.delete('all')
display_pallete()
window = Tk()
window.title('Paint')
window.state('zoomed')
window.rowconfigure(0, weight=1)
window.columnconfigure(0, weight=1)
menubar = Menu(window)
window.config(menu = menubar)
submenu = Menu(menubar,tearoff=0)
menubar.add_cascade(label='File', menu=submenu)
submenu.add_command(label='New Canvas', command=new_canvas)
canvas= Canvas(window)
canvas.grid(row=0,column=0,sticky='nsew')
canvas.bind('<Button-1>', locate_xy)
canvas.bind('<B1-Motion>',addLine)
def display_pallete():
id = canvas.create_rectangle((10,10,30,30),fill='black')
canvas.tag_bind(id, '<Button-1>', lambda x: show_color('black'))
id = canvas.create_rectangle((10,40,30,60),fill='gray')
canvas.tag_bind(id, '<Button-1>', lambda x: show_color('gray'))
id = canvas.create_rectangle((10,70,30,90),fill='brown4')
canvas.tag_bind(id, '<Button-1>', lambda x: show_color('brown4'))
id = canvas.create_rectangle((10,100,30,120),fill='red')
canvas.tag_bind(id, '<Button-1>', lambda x: show_color('red'))
id = canvas.create_rectangle((10,130,30,150),fill='orange')
canvas.tag_bind(id, '<Button-1>', lambda x: show_color('orange'))
id = canvas.create_rectangle((10,160,30,180),fill='yellow')
canvas.tag_bind(id, '<Button-1>', lambda x: show_color('yellow'))
id = canvas.create_rectangle((10,190,30,210),fill='green')
canvas.tag_bind(id, '<Button-1>', lambda x: show_color('green'))
id = canvas.create_rectangle((10,220,30,240),fill='blue')
canvas.tag_bind(id, '<Button-1>', lambda x: show_color('blue'))
id = canvas.create_rectangle((10,250,30,270),fill='purple')
canvas.tag_bind(id, '<Button-1>', lambda x: show_color('purple'))
display_pallete()
window.mainloop()
# from tkinter import *
# import pyttsx3
# import pygame
# pygame.mixer.init()
# engine = pyttsx3.init()
# root = Tk()
# def read():
# outfile = "temp.wav"
# engine.save_to_file(text.get('1.0', END), outfile)
# engine.runAndWait()
# pygame.mixer.music.load(outfile)
# pygame.mixer.music.play()
# def stop():
# pygame.mixer.music.stop()
# def pause():
# pygame.mixer.music.pause()
# def unpause():
# pygame.mixer.music.unpause()
# text = Text(width=65, height=20, font="consolas 14")
# text.pack()
# text.insert(END, "This is a text widget\n"*10)
# read_button = Button(root, text="Read aloud", command=read)
# read_button.pack(pady=20)
# pause_button = Button(root, text="Pause", command=pause)
# pause_button.pack()
# unpause_button = Button(root, text="Unpause", command=unpause)
# unpause_button.pack(pady=20)
# stop_button = Button(root, text="Stop", command=stop)
# stop_button.pack()
# mainloop()