-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
52 lines (33 loc) · 989 Bytes
/
gui.py
File metadata and controls
52 lines (33 loc) · 989 Bytes
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
import tkinter as tk
import pygame
# 初始化 pygame
pygame.mixer.init()
is_playing = False
music_duration = 0
# 通過 Pygame 實現 GUI
def play_music():
global is_playing
if not is_playing:
pygame.mixer.music.load('/Users/rich/Desktop/AI-music/Generated_Music/CVAEgenerated_music_0.mid')
pygame.mixer.music.play()
is_playing = True
def pause_music():
global is_playing
if is_playing:
pygame.mixer.music.pause()
is_playing = False
def stop_music():
global is_playing
if is_playing:
pygame.mixer.music.stop()
is_playing = False
# 創建窗口
window = tk.Tk()
# 設置窗口大小和按鈕
play_button = tk.Button(window, text="播放", command=play_music)
play_button.pack(pady=10)
pause_button = tk.Button(window, text="暫停", command=pause_music)
pause_button.pack(pady=5)
stop_button = tk.Button(window, text="停止", command=stop_music)
stop_button.pack(pady=5)
window.mainloop()