-
Notifications
You must be signed in to change notification settings - Fork 0
/
emoji_picker.py
72 lines (60 loc) · 3.85 KB
/
emoji_picker.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
import customtkinter as ctk # type: ignore
from tkinter import Label, font as tkfont
from constants import (
PRIMARY_COLOR,
)
class EmojiPicker(ctk.CTkToplevel):
def __init__(self, master, callback, theme):
super().__init__(master)
self.title("Emoji Picker")
self.geometry("400x400")
self.theme = theme
self.configure(fg_color=self.theme.bg)
self.callback = callback
self.emoji_list = [
"😀", "😃", "😄", "😁", "😆", "😅", "😂", "🤣", "😊", "😇", "🙂", "🙃", "😉", "😌", "😍", "🥰", "😘", "😗", "😙", "😚",
"😋", "😛", "😝", "😜", "🤪", "🤨", "🧐", "🤓", "😎", "🤩", "🥳", "😏", "😒", "😞", "😔", "😟", "😕", "🙁", "☹️", "😣",
"😖", "😫", "😩", "🥺", "😢", "😭", "😤", "😠", "😡", "🤬", "🤯", "😳", "🥵", "🥶", "😱", "😨", "😰", "😥", "😓", "🤗",
"🤔", "🤭", "🤫", "🤥", "😶", "😐", "😑", "😬", "🙄", "😯", "😦", "😧", "😮", "😲", "🥱", "😴", "🤤", "😪", "😵", "🤐",
"🥴", "🤢", "🤮", "🤧", "😷", "🤒", "🤕", "🤑", "🤠", "😈", "👿", "👹", "👺", "🤡", "💩", "👻", "💀", "☠️", "👽", "👾",
"🤖", "🎃", "😺", "😸", "😹", "😻", "😼", "😽", "🙀", "😿", "😾", "👋", "🤚", "🖐", "✋", "🖖", "👌", "🤌", "🤏", "✌️",
"🤞", "🤟", "🤘", "🤙", "👈", "👉", "👆", "🖕", "👇", "☝️", "👍", "👎", "✊", "👊", "🤛", "🤜", "👏", "🙌", "👐", "🤲",
"🤝", "🙏", "✍️", "💅", "🤳", "💪", "🦾", "🦵", "🦿", "🦶", "👣", "👂", "🦻", "👃", "🫀", "🫁", "🧠", "🦷", "🦴", "👀",
"👁", "👅", "👄", "💋", "🩸", "🐵", "🐒", "🦍", "🦧", "🐶", "🐕", "🦮", "🐩", "🐺", "🦊", "🦝", "🐱", "🐈", "🦁", "🐯",
"🐅", "🐆", "🐴", "🐎", "🦄", "🦓", "🦌", "🦬", "🐮", "🐂", "🐃", "🐄", "🐷", "🐖", "🐗", "🐽", "🐏", "🐑", "🐐", "🐪"
]
self.create_emoji_buttons()
def create_emoji_buttons(self):
# Create a canvas with scrollbar
canvas = ctk.CTkCanvas(self, bg=self.theme.bg, highlightthickness=0)
scrollbar = ctk.CTkScrollbar(self, orientation="vertical", command=canvas.yview)
# Create a frame inside the canvas
self.scrollable_frame = ctk.CTkFrame(canvas, fg_color=self.theme.bg)
self.scrollable_frame.bind(
"<Configure>",
lambda e: canvas.configure(scrollregion=canvas.bbox("all"))
)
canvas.create_window((0, 0), window=self.scrollable_frame, anchor="nw")
canvas.configure(yscrollcommand=scrollbar.set)
# Try different fonts
emoji_fonts = ["Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", "Twitter Color Emoji", "EmojiOne Color"]
emoji_font = None
for font_name in emoji_fonts:
try:
emoji_font = tkfont.Font(family=font_name, size=24)
break
except:
continue
if emoji_font is None:
emoji_font = tkfont.nametofont("TkDefaultFont").copy()
emoji_font.config(size=24)
# Create labels for each emoji
for i, emoji_char in enumerate(self.emoji_list):
label = Label(self.scrollable_frame, text=emoji_char, font=emoji_font, bg=self.theme.bg)
label.grid(row=i // 8, column=i % 8, padx=2, pady=2)
label.bind("<Button-1>", lambda e, emoji=emoji_char: self.select_emoji(emoji))
canvas.pack(side="left", fill="both", expand=True)
scrollbar.pack(side="right", fill="y")
def select_emoji(self, emoji):
self.callback(emoji)
self.destroy()