forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemoji_dictionary.py
More file actions
350 lines (301 loc) · 8.1 KB
/
Copy pathemoji_dictionary.py
File metadata and controls
350 lines (301 loc) · 8.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# Emoji Dictionary
# -----------------------------------------------------------------------------------------------------
import io # used for dealing with input and output
from tkinter import * # importing the necessary libraries
import tkinter.messagebox as mbox
import tkinter as tk # imported tkinter as tk
import emoji
# -----------------------------------------------------------------------------------------------
class Keypad(tk.Frame):
cells = [
["😀", "🥰", "😴", "🤓", "🤮", "🤬", "😨", "🤑", "😫", "😎"],
[
"🐒",
"🐕",
"🐎",
"🐪",
"🐁",
"🐘",
"🦘",
"🦈",
"🐓",
"🐝",
"👀",
"🦴",
"👩🏿",
"🤝",
"🧑",
"🏾",
"👱🏽",
"♀",
"🎞",
"🎨",
"⚽",
],
[
"🍕",
"🍗",
"🍜",
"☕",
"🍴",
"🍉",
"🍓",
"🌴",
"🌵",
"🛺",
"🚲",
"🛴",
"🚉",
"🚀",
"✈",
"🛰",
"🚦",
"🏳",
"🌈",
"🌎",
"🧭",
],
[
"🔥",
"❄",
"🌟",
"🌞",
"🌛",
"🌝",
"🌧",
"🧺",
"🧷",
"🪒",
"⛲",
"🗼",
"🕌",
"👁",
"🗨",
"💬",
"™",
"💯",
"🔕",
"💥",
"❤",
],
]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.target = None
self.memory = ""
for y, row in enumerate(self.cells):
for x, item in enumerate(row):
b = tk.Button(
self,
text=item,
command=lambda text=item: self.append(text),
font=("Arial", 14),
bg="yellow",
fg="blue",
borderwidth=3,
relief="raised",
)
b.grid(row=y, column=x, sticky="news")
x = tk.Button(
self,
text="Space",
command=self.space,
font=("Arial", 14),
bg="yellow",
fg="blue",
borderwidth=3,
relief="raised",
)
x.grid(row=0, column=10, columnspan="2", sticky="news")
x = tk.Button(
self,
text="tab",
command=self.tab,
font=("Arial", 14),
bg="yellow",
fg="blue",
borderwidth=3,
relief="raised",
)
x.grid(row=0, column=12, columnspan="2", sticky="news")
x = tk.Button(
self,
text="Backspace",
command=self.backspace,
font=("Arial", 14),
bg="yellow",
fg="blue",
borderwidth=3,
relief="raised",
)
x.grid(row=0, column=14, columnspan="3", sticky="news")
x = tk.Button(
self,
text="Clear",
command=self.clear,
font=("Arial", 14),
bg="yellow",
fg="blue",
borderwidth=3,
relief="raised",
)
x.grid(row=0, column=17, columnspan="2", sticky="news")
x = tk.Button(
self,
text="Hide",
command=self.hide,
font=("Arial", 14),
bg="yellow",
fg="blue",
borderwidth=3,
relief="raised",
)
x.grid(row=0, column=19, columnspan="2", sticky="news")
def get(self):
if self.target:
return self.target.get()
def append(self, text):
if self.target:
self.target.insert("end", text)
def clear(self):
if self.target:
self.target.delete(0, END)
def backspace(self):
if self.target:
text = self.get()
text = text[:-1]
self.clear()
self.append(text)
def space(self):
if self.target:
text = self.get()
text = text + " "
self.clear()
self.append(text)
def tab(self): # 5 spaces
if self.target:
text = self.get()
text = text + " "
self.clear()
self.append(text)
def copy(self):
# TODO: copy to clipboad
if self.target:
self.memory = self.get()
self.label["text"] = "memory: " + self.memory
print(self.memory)
def paste(self):
# TODO: copy from clipboad
if self.target:
self.append(self.memory)
def show(self, entry):
self.target = entry
self.place(relx=0.5, rely=0.6, anchor="c")
def hide(self):
self.target = None
self.place_forget()
# function defined th=o clear both the input text and output text --------------------------------------------------
def clear_text():
inputentry.delete(0, END)
outputtxt.delete("1.0", "end")
# function to search emoji
def search_emoji():
word = inputentry.get()
if word == "":
outputtxt.insert(END, "You have entered no emoji.")
else:
means = emoji.demojize(word)
outputtxt.insert(END, "Meaning of Emoji : " + str(word) + "\n\n" + means)
# main window created
window = tk.Tk()
window.title("Emoji Dictionary")
window.geometry("1000x700")
# for writing Dictionary label, at the top of window
dic = tk.Label(
text="EMOJI DICTIONARY", font=("Arial", 50, "underline"), fg="magenta"
) # same way bg
dic.place(x=160, y=10)
start1 = tk.Label(
text="Enter any Emoji you want to search...", font=("Arial", 30), fg="green"
) # same way bg
start1.place(x=160, y=120)
myname = StringVar(window)
firstclick1 = True
def on_inputentry_click(event):
"""function that gets called whenever entry1 is clicked"""
global firstclick1
if firstclick1: # if this is the first time they clicked it
firstclick1 = False
inputentry.delete(0, "end") # delete all the text in the entry
# Taking input from TextArea
# inputentry = Entry(window,font=("Arial", 35), width=33, border=2)
inputentry = Entry(
window, font=("Arial", 35), width=28, border=2, bg="light yellow", fg="brown"
)
inputentry.place(x=120, y=180)
# # Creating Search Button
Button(
window,
text="🔍 SEARCH",
command=search_emoji,
font=("Arial", 20),
bg="light green",
fg="blue",
borderwidth=3,
relief="raised",
).place(x=270, y=250)
# # creating clear button
Button(
window,
text="🧹 CLEAR",
command=clear_text,
font=("Arial", 20),
bg="orange",
fg="blue",
borderwidth=3,
relief="raised",
).place(x=545, y=250)
# meaning label
start1 = tk.Label(text="Meaning...", font=("Arial", 30), fg="green") # same way bg
start1.place(x=160, y=340)
# # Output TextBox Creation
outputtxt = tk.Text(
window,
height=7,
width=57,
font=("Arial", 17),
bg="light yellow",
fg="brown",
borderwidth=3,
relief="solid",
)
outputtxt.place(x=120, y=400)
# function for exiting
def exit_win():
if mbox.askokcancel("Exit", "Do you want to exit?"):
window.destroy()
# # creating exit button
Button(
window,
text="❌ EXIT",
command=exit_win,
font=("Arial", 20),
bg="red",
fg="black",
borderwidth=3,
relief="raised",
).place(x=435, y=610)
keypad = Keypad(window)
# # creating speech to text button
v_keypadb = Button(
window,
text="⌨",
command=lambda: keypad.show(inputentry),
font=("Arial", 18),
bg="light yellow",
fg="green",
borderwidth=3,
relief="raised",
).place(x=870, y=183)
window.protocol("WM_DELETE_WINDOW", exit_win)
window.mainloop()