-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
152 lines (135 loc) · 5.21 KB
/
main.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
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
import qrcode
from customtkinter import *
from PIL import ImageTk
# по дефолту светлая тема
current_theme = "light"
# осуществление функционала кнопки для смены темы
def theme_button_calllback():
global current_theme
if current_theme == "light":
set_appearance_mode("dark")
current_theme = "dark"
else:
set_appearance_mode("light")
current_theme = "light"
# генерация и вывод кью ар кода
def generate_qr():
global current_theme # получаем текущую тему
if current_theme == "dark":
back_color = "#f2bf2b"
fill_color = "#252525"
else:
back_color = "grey"
fill_color = "white"
link = entry.get() # получаем введенный текст
qr = qrcode.QRCode(version=15, box_size=10, border=5)
qr.add_data(link)
qr.make(fit=True)
img = qr.make_image(fill_color=fill_color, back_color=back_color)
img = img.resize((300, 300)) # меняю размер чтобы красиво было
img = ImageTk.PhotoImage(img) # преобразуем в удобный формат
label = CTkLabel(app, image=img, text="")
label.place(relx=0.6, rely=0.25) # постим на экран
text = CTkLabel(master=app, text=link, text_color="grey")
text.place(relx=0.6, rely=0.20) # выводим текст над кью ар кодом
# функционал кнобки эбаут
def about_button_calllback():
about_window = CTk() # создаем второе окно
about_window.geometry("600x300")
info = CTkLabel(
master=about_window,
text=""""QR Code Generator App"
Create personalized QR codes effortlessly!
This intuitive application lets you swiftly generate QR codes from links.
Experience a sleek interface designed using customtkinter, an advanced UI library.
Just input your link, click 'Generate QR code', and voilà!
The generated QR code is ready to use.
Explore the dynamic blend of aesthetics and functionality.
Features:
Generate QR codes from links
Stylish and user-friendly design
Powered by customtkinter and qrcode
Unleash the power of QR codes with ease.
Elevate your link sharing experience today!""",
font=("Arial", 12),
fg_color="goldenrod1",
anchor="center",
text_color="black",
corner_radius=6
)
info.place(relx=0.1, rely=0.1)
about_window.mainloop()
# создаем главное окно
app = CTk()
app.title("QR-Maker")
set_appearance_mode("light")
app.geometry("920x620")
# делаем фрейм для удобного расположения элементов
frame = CTkFrame(master=app)
frame.place(relx=0, rely=0.1, relwidth=0.5, relheight=0.7)
# это тот огромный текст по середине
welcome_text = CTkLabel(
master=frame,
text="_put link below_",
font=("Arial", 45, "bold"),
fg_color=f"goldenrod1",
text_color="black",
anchor="center",
corner_radius=6
)
welcome_text.place(relx=0.1, rely=0.3)
# полее ввода для ссылки
entry = CTkEntry(master=frame, width=300, height=30,
border_color="black",
placeholder_text="https://www.youtube.com/") # текст заглушка, который видно по дефолту
entry.place(relx=0.47, rely=0.6, anchor="center")
# кнопка генерации кода
button_gen = CTkButton(master=frame)
button_gen.configure(fg_color="goldenrod1",
text="Generate QR code",
text_color="black",
hover_color="goldenrod2",
width=50,
height=30,
corner_radius=6,
border_width=1,
border_color="grey29",
command=generate_qr)
button_gen.place(relx=0.47, rely=0.7, anchor="center")
# кнопка эбаут
button_about = CTkButton(master=app)
button_about.configure(fg_color="goldenrod1",
text="About",
text_color="black",
hover_color="goldenrod2",
width=50,
height=30,
corner_radius=6,
border_width=1,
border_color="grey29",
command=about_button_calllback)
button_about.pack(side='left', anchor='nw', padx=10, pady=10)
# кнопка темы
button_theme = CTkButton(master=app)
button_theme.configure(fg_color="goldenrod1",
text="Theme",
text_color="black",
hover_color="goldenrod2",
width=50,
height=30,
corner_radius=6,
border_width=1,
border_color="grey29",
command=theme_button_calllback)
button_theme.pack(side='right', anchor='nw', padx=10, pady=10)
# мини текст снизу страницы
author = CTkLabel(
master=app,
text="_by nik1t7n_",
font=("Arial", 12),
fg_color="transparent",
anchor="center",
text_color="grey"
)
author.place(relx=0.5, rely=0.95)
app.mainloop()