Skip to content

Commit 96cf7ad

Browse files
author
nanocode38
committed
prepare V1.0.0
1 parent 457c3d9 commit 96cf7ad

File tree

5 files changed

+93
-92
lines changed

5 files changed

+93
-92
lines changed

README-CH.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Sound Keyboard
2-
- [Endlish version 英文版本](./README.md)
2+
- [English Version 英文版本](./README.md)
33

44
## 简介
55
有声键盘是一个简单的软件, 此软件由Python实现, 使用到了pygame, tkinter, pynput等一些库.
@@ -11,12 +11,12 @@
1111

1212
效果如图:
1313

14-
![预览](image.png)
14+
![预览](images/preview.png)
1515

16-
![预览](image-1.png)
16+
![预览](images/preview-1.png)
1717

1818
*注:Sound Keyboard允许自定义键盘声音文件*
1919

2020
## 打赏
2121

22-
*非常抱歉,打赏码已过期,请考虑以后再进行打赏*
22+
*非常抱歉,打赏码已过期,请考虑以后再进行打赏*

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Sound Keyboard
2-
- [Chinese version 中文版本](./README-CH.md)
2+
- [Chinese Version 中文版本](./README-CH.md)
33

44
## Introduction
55
Sound Keyboard is a simple software implemented in Python. It utilizes libraries such as pygame, tkinter, pynput, etc.
@@ -11,12 +11,12 @@ Sound Keyboard is a simple software implemented in Python. It utilizes libraries
1111

1212
Preview:
1313

14-
![Preview](image.png)
14+
![Preview](images/preview.png)
1515

16-
![Preview](image-1.png)
16+
![Preview](images/previewEN.png)
1717

1818
*Note: Sound Keyboard allows customization of keyboard sound files*
1919

2020
## Donation
2121

22-
*Sorry, the donation code has expired. Please consider donating later*
22+
![Preview](images\support.png)

image-1.png

-29.8 KB
Binary file not shown.

image.png

-7.41 KB
Binary file not shown.

main.py

Lines changed: 85 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
from sys import exit
77
from pathlib import Path
88

9-
import pygame
9+
10+
import pygame.mixer
1011
from pynput import keyboard
1112
from pynput.keyboard import Key
1213

@@ -34,27 +35,35 @@
3435
'not file':'此路径不是文件',
3536
'exit':'退出系统',
3637
'ok':'确 定',
37-
'about':'关于',
3838
'set':'设置',
3939
'lau':'英语English',
40-
'about str':"""音效键盘系统
40+
'about title': '关于',
41+
'about':"""音效键盘系统
4142
属于: nanocode38 Copyright(C)
42-
官方网站: https://github.com/nanocode38/audio_keyboard""",
43+
官方网站: https://github.com/nanocode38/audio_keyboard
44+
赞助一下:
45+
""",
4346
'calc':'取 消',
47+
'language text': '语言设置(Language):',
48+
'reset': '恢复原路径'
4449
},
4550
'English':[
4651
'Keyboard audio file settings:',
4752
'This file is not an audio file',
4853
'This path is not a file',
4954
'Exit System',
5055
'O K',
51-
'About',
5256
'Settings',
5357
'Chinese中文',
58+
'About',
5459
"""Sound keyboard system
5560
Subject to: nanocode38 Copyright (C)
56-
Official website: https://github.com/nanocode38/audio_keyboard""",
61+
Official website: https://github.com/nanocode38/audio_keyboard
62+
Sponsorship:
63+
""",
5764
'Cancel',
65+
'Language(语言设置):',
66+
'recover'
5867
]
5968
}
6069

@@ -66,6 +75,7 @@
6675
LANGUAGE_LIST['English'] = e
6776
del e, i
6877

78+
6979
continuous_button = {
7080
Key.ctrl_l: False,
7181
Key.ctrl_r: False,
@@ -94,6 +104,8 @@
94104
language = str(pickle.load(f))
95105
no_sound = bool(pickle.load(f))
96106

107+
108+
sounds_path = os.path.abspath(sounds_path)
97109
def _exit():
98110
global sounds_path, no_sound
99111
with open(home_path / 'AudioKeyBoard' / 'audio_keyboard_data.dat', 'wb') as f:
@@ -138,35 +150,32 @@ def out(key):
138150
listener_thread.daemon = True # 将监听器线程设置为守护进程
139151
listener_thread.start()
140152

141-
def get_new_main_root():
142-
global root, sound_image, about_button, exit_button, move_button, settings_button, sound_button, settings_image
143-
global LANGUAGE_LIST, language, no_sound, no_sound_image, sound_image, get_about, get_settings, _exit, exit_image
144-
root = tk.Tk()
145-
root.overrideredirect(1)
146-
root.wm_attributes('-alpha', 0.8)
153+
154+
def get_new_main_root(isnooroot=True):
155+
global root, sound_image, about_button, exit_button, move_button, settings_image
156+
global LANGUAGE_LIST, language, no_sound, no_sound_image, sound_image, get_about
157+
global logo, get_settings, _exit, exit_image, settings_button, sound_button
158+
if isnooroot:
159+
root = tk.Tk()
160+
root.overrideredirect(True)
161+
root.wm_attributes('-alpha', 0.7)
147162
root.wm_attributes('-toolwindow', True)
148163
root.wm_attributes('-topmost', True)
149-
root.geometry('210x25+400+500')
164+
root.geometry('175x25+500+600')
150165
root.update()
151166

152167
sound_image = tk.PhotoImage(file=r".\images\sound_button.png")
153-
154168
no_sound_image = tk.PhotoImage(file=r".\images\no_sound_button.png")
155-
156169
settings_image = tk.PhotoImage(file=r'.\images\settings.png')
157-
158170
exit_image = tk.PhotoImage(file=r'.\images\exit.png')
171+
logo_image = tk.PhotoImage(file=r'.\images\logo.png')
159172

160-
# logo_image = tk.PhotoImage(file=r'.\images\Logo.ico
161-
162-
about_button = tk.Button(root, text=LANGUAGE_LIST[language]['about'], command=get_about)
163-
about_button.place(x=120, y=0)
164173

165174
settings_button = tk.Button(root, image=settings_image, command=get_settings)
166-
settings_button.pack()
175+
settings_button.place(x=10, y=0)
167176

168177
exit_button = tk.Button(root, image=exit_image, command=_exit)
169-
exit_button.place(x=40, y=0)
178+
exit_button.place(x=39, y=0)
170179

171180
move_button = tk.Button(root)
172181
# 绑定按下和松开事件
@@ -179,7 +188,10 @@ def get_new_main_root():
179188
sound_button = tk.Button(root, image=no_sound_image, command=loudspeaker_mute)
180189
else:
181190
sound_button = tk.Button(root, image=sound_image, command=loudspeaker_mute)
182-
sound_button.place(x=180, y=-2)
191+
sound_button.place(x=110, y=-1)
192+
193+
logo = tk.Button(root, image=logo_image, command=get_about)
194+
logo.place(x=146, y=-3)
183195

184196
root.mainloop()
185197

@@ -221,8 +233,8 @@ def loudspeaker_mute():
221233

222234

223235
def get_settings():
224-
global sounds_path, LANGUAGE_LIST, language
225-
global root
236+
global sounds_path, LANGUAGE_LIST
237+
global root, language
226238
settings_windows = tk.Toplevel(root)
227239
settings_windows.title(LANGUAGE_LIST[language]['set'])
228240
settings_windows.wm_attributes('-alpha', 0.8)
@@ -234,13 +246,15 @@ def get_settings():
234246
label.grid(row=0, column=0)
235247

236248
path_entry = tk.Entry(settings_windows, bd=3, width=51)
237-
path_entry.insert(0, sounds_path)
249+
if sounds_path[1] != ':':
250+
path_entry.insert(0, sounds_path)
251+
else:
252+
path_entry.insert(0, sounds_path)
238253
path_entry.place(x=1, y=30)
239-
240254
get = False
241255
def get_message():
242-
global sounds_path
243-
global get
256+
global sounds_path, LANGUAGE_LIST
257+
global get, language
244258
get = True
245259
from tkinter import filedialog
246260
f_path = filedialog.askopenfilename(title='Open Sounds File')
@@ -253,8 +267,12 @@ def get_message():
253267
path_entry.delete(0, tk.END)
254268
path_entry.insert(0, f_path)
255269

270+
old_language = language
271+
newlanguage = tk.StringVar()
272+
newlanguage.set(old_language)
256273
def ok():
257-
global sounds_path
274+
global sounds_path, language
275+
language = newlanguage.get()
258276
if not get:
259277
f_path = path_entry.get()
260278
if f_path != '':
@@ -266,7 +284,13 @@ def ok():
266284
messagebox.showerror(title='File Error', message=LANGUAGE_LIST[language]['no sounds'])
267285
else:
268286
sounds_path = f_path
269-
settings_windows.destroy()
287+
288+
if old_language != language:
289+
root.destroy()
290+
get_new_main_root()
291+
292+
else:
293+
settings_windows.destroy()
270294

271295
path_button = tk.Button(settings_windows, text='. . .', command=get_message)
272296
ok_button = tk.Button(settings_windows, width=10, text=LANGUAGE_LIST[language]['ok'], command=ok)
@@ -276,21 +300,27 @@ def ok():
276300
ok_button.place(x=250, y=330)
277301
no_button.place(x=320, y=330)
278302

303+
def reset():
304+
get = False
305+
s_path = Path.cwd()
306+
s_path = s_path / 'sounds' / 'KeyBoard.mp3'
307+
path_entry.delete(0, tk.END)
308+
path_entry.insert(0, s_path)
309+
279310
exit_button = tk.Button(settings_windows, text=LANGUAGE_LIST[language]['exit'], command=_exit)
280-
exit_button.place(x=250, y=100)
311+
exit_button.place(x=10, y=330)
312+
313+
reset_button = tk.Button(settings_windows, text=LANGUAGE_LIST[language]['reset'], command=reset)
314+
reset_button.place(x=10, y=55)
315+
281316

282-
def changing_over_language():
283-
global root
284-
global language
285-
if language == 'Chinese':
286-
language = 'English'
287-
else:
288-
language = 'Chinese'
289-
root.destroy()
290-
get_new_main_root()
317+
la_text = tk.Label(settings_windows, text=LANGUAGE_LIST[language]['language text'])
318+
la_text.place(x=5, y=100)
319+
chinese_radiobutton = tk.Radiobutton(settings_windows, text='简体中文', variable=newlanguage, value='Chinese')
320+
english_radiobutton = tk.Radiobutton(settings_windows, text='English(USA)', variable=newlanguage, value='English')
321+
chinese_radiobutton.place(x=50, y=130)
322+
english_radiobutton.place(x=50, y=160)
291323

292-
language_button = tk.Button(settings_windows, text=LANGUAGE_LIST[language]['lau'], command=changing_over_language)
293-
language_button.place(x=100, y=200)
294324

295325

296326
settings_windows.update()
@@ -300,54 +330,25 @@ def changing_over_language():
300330
def get_about():
301331
global root, language, LANGUAGE_LIST
302332
about_windows = tk.Toplevel(root)
303-
about_windows.title(LANGUAGE_LIST[language]['about'])
333+
about_windows.title(LANGUAGE_LIST[language]['about title'])
304334
about_windows.wm_attributes('-alpha', 0.8)
305335
about_windows.wm_attributes('-topmost', True)
306-
about_windows.geometry('400x360+300+250')
336+
about_windows.geometry('500x620+100+5')
307337
about_windows.iconbitmap(r'./images/Logo.ico')
308338

309-
about_text = LANGUAGE_LIST[language]['about str']
339+
about_text = LANGUAGE_LIST[language]['about']
310340

311-
label = tk.Label(about_windows, text=about_text)
312-
label.grid(row=0, column=0)
313-
314-
315-
root = tk.Tk()
316-
root.overrideredirect(True)
317-
root.wm_attributes('-alpha', 0.8)
318-
root.wm_attributes('-toolwindow', True)
319-
root.wm_attributes('-topmost', True)
320-
root.geometry('210x25+400+500')
321-
root.update()
341+
text_label = tk.Label(about_windows, text=about_text, justify=tk.CENTER)
342+
text_label.pack()
322343

323-
sound_image = tk.PhotoImage(file=r".\images\sound_button.png")
344+
support_image = tk.PhotoImage(file=r'.\images\support.png')
345+
support_image = support_image.subsample(2, 2)
346+
support_label = tk.Label(about_windows, image=support_image)
347+
support_label.pack()
324348

325-
no_sound_image = tk.PhotoImage(file=r".\images\no_sound_button.png")
349+
about_windows.mainloop()
326350

327-
settings_image = tk.PhotoImage(file=r'.\images\settings.png')
328351

329-
exit_image = tk.PhotoImage(file=r'.\images\exit.png')
330352

331-
about_button = tk.Button(root, text=LANGUAGE_LIST[language]['about'], command=get_about)
332-
about_button.place(x=120, y=0)
333-
334-
settings_button = tk.Button(root, image=settings_image, command=get_settings)
335-
settings_button.pack()
336-
337-
exit_button = tk.Button(root, image=exit_image, command=_exit)
338-
exit_button.place(x=40, y=0)
339-
340-
move_button = tk.Button(root)
341-
# 绑定按下和松开事件
342-
move_button.bind("<ButtonPress-1>", start_move)
343-
move_button.bind("<ButtonRelease-1>", stop_move)
344-
move_button.bind("<B1-Motion>", on_motion)
345-
move_button.place(x=-1, y=0)
346-
347-
if no_sound:
348-
sound_button = tk.Button(root, image=no_sound_image, command=loudspeaker_mute)
349-
else:
350-
sound_button = tk.Button(root, image=sound_image, command=loudspeaker_mute)
351-
sound_button.place(x=180, y=-2)
352-
353-
root.mainloop()
353+
root = tk.Tk()
354+
get_new_main_root(False)

0 commit comments

Comments
 (0)