PyGameとTkinterで作りましたが、Pythonに機能が足りず、完成が遠のきました。音楽再生と停止の機能は現時点でも使えますが、他の機能が作れずという感じで終わりました。Python自体は便利なんだけどね・・・w
Python
import tkinter
import tkinter.filedialog
from tkinter import ttk
from ttkthemes import ThemedTk
import pygame
import os
home = os.environ['HOME']
def button_play_clicked(event):
record_id = treeview_playlists.focus()
record_values = treeview_playlists.item(record_id, "values")
if record_values[1].startswith("~"):
path = home + record_values[1][1:]
pygame.mixer.init()
pygame.mixer.music.load(path)
pygame.mixer.music.play(1)
print("Playing...")
def button_stop_clicked(event):
pygame.mixer.music.stop()
print("Stopped.")
def treeview_playlists_clicked(event):
record_id = treeview_playlists.focus()
record_values = treeview_playlists.item(record_id, "values")
if record_values[1].startswith("~"):
path = home + record_values[1][1:]
pygame.mixer.init()
pygame.mixer.music.load(path)
pygame.mixer.music.play(1)
print("Selection Playing...")
def open_file_dialog(event=None):
iid = 0
file_types = [("音楽ファイル","*")]
file_dialog_current_path = home + "/Music"
file_paths = tkinter.filedialog.askopenfilenames(filetypes=file_types, initialdir=file_dialog_current_path)
for path in file_paths:
tmp_path = path
if tmp_path.startswith(home):
tmp_path = tmp_path.replace(home, "~")
treeview_playlists.insert(parent="", index="end", iid=iid, values=(os.path.splitext(os.path.basename(tmp_path))[0], tmp_path))
iid += 1
root = ThemedTk(theme="equilux")
root.title("Original Music Player")
root.geometry("640x480")
menu_bar = tkinter.Menu(root, fg="#fff", bg="#111", bd=0)
root.config(menu=menu_bar)
file_menu = tkinter.Menu(menu_bar, tearoff=False)
menu_bar.add_cascade(label="ファイル", menu=file_menu)
file_menu.add_command(label="ファイルを開く", command=open_file_dialog)
help_menu = tkinter.Menu(menu_bar, tearoff=False)
menu_bar.add_cascade(label="ヘルプ", menu=help_menu)
help_menu.add_command(label="バージョン情報")
ttk.Style().configure("Treeview", foreground="#fff", background="#111", fieldbackground="#111", rowheight=20, highlightthickness=0, bd=0)
frame = tkinter.Frame(root, width=640, height=480, highlightthickness=0, bd=0)
frame.propagate(False)
frame.pack(side="left", fill="both", expand=True)
inner_frame = tkinter.Frame(frame, height=60, relief=tkinter.RAISED, bg="#222", highlightthickness=0, bd=0)
inner_frame.grid_propagate(False)
button_play = tkinter.Button(inner_frame, text="Play!", width=5, fg="white", bg="#333", highlightthickness=0, bd=0)
button_stop = tkinter.Button(inner_frame, text="Stop", width=5, fg="white", bg="#333", highlightthickness=0, bd=0)
inner_frame.pack(side="top", fill="x")
button_play.grid(row=0, column=0, padx=10, pady=10)
button_stop.grid(row=0, column=1)
inner_frame_playlists = tkinter.Frame(frame, relief=tkinter.RAISED, highlightthickness=0, bd=0)
inner_frame_playlists.propagate(False)
treeview_playlists = ttk.Treeview(inner_frame_playlists)
treeview_playlists["columns"] = ("Name","Path")
treeview_playlists.column("#0", width=0, stretch="no")
treeview_playlists.column("Name", anchor="nw", width=100)
treeview_playlists.column("Path", anchor="nw", width=120)
treeview_playlists.heading("#0", text="Label", anchor="nw")
treeview_playlists.heading("Name", text="Name", anchor="nw")
treeview_playlists.heading("Path", text="Path", anchor="nw")
inner_frame_playlists.pack(side="bottom", fill="both", expand=True)
treeview_playlists.pack(side="left", fill="both", expand=True)
button_play.bind("<Button-1>", button_play_clicked)
button_stop.bind("<Button-1>", button_stop_clicked)
treeview_playlists.bind("<Double-Button-1>", treeview_playlists_clicked)
root.mainloop()