今日の成果
ファイル構成
main.py
SongData
└あいみょん
└マリーゴールド.csv
Tkinterで画面の表示と、1曲のコードを表示させました。(マリーゴールド/あいみょん)
将来的にSongDataフォルダからフォルダ名を読み込んで赤い部分に表示、選択すると右側の緑部分に曲名が入り、さらに選択すると下部に表示される仕組みにさせていきたいと思っています。
実行画面
コード詳細
基本はTkinterの記事を参照してください。https://zackblog7.com/%e3%80%90python%e3%80%91%e3%82%a6%e3%82%a3%e3%83%b3%e3%83%89%e3%82%a6%e8%a1%a8%e7%a4%ba%e3%81%ae%e5%9f%ba%e7%a4%8e%e3%80%90tkinter%e3%80%91/
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 |
# GUI表示で利用 import tkinter as tk from tkinter import filedialog, messagebox # ファイルとディレクトリの操作に使用 import os import csv import time w_width = 1000 w_height = 2400 w_tph = 200 Codebase = ["A","Ab","B","C","Db","D","Eb","E","F","F#","G","Ab"] def openSongData(url = "SongData/あいみょん/マリーゴールド.csv"): with open(url,encoding="utf-8-sig") as file: x = list(csv.reader(file)) y = x[0] y = [a for a in y if a != ''] print(y) for n ,i in enumerate(x): if n == 0: print(str(i[1])) elif n == 1: print("酢きっぴゅ") elif n % 2 == 0: for m, j in enumerate(i): if m == 0: # print(f"{m}と{j}") pass elif m == 17: pass else: z = C_lbl[n//2-1][m-1] z["text"] = j pass elif n % 2 == 1: for m, j in enumerate(i): if m == 0: # print(f"{m}と{j}") pass elif m == 17: pass else: z = K_lbl[n//2-1][m-1] if j == "": z.place_forget() pass else: z["text"] = j pass root = tk.Tk() root.geometry(f"{w_width}x{w_height}") root.resizable(width = False, height= False) # root.attributes("-alpha", 0.5) # root.iconbitmap(default="icontest.ico") # root.option_add("*font", ('', 14)) root.title("コードくん") t_frame = tk.Frame(root, width = w_width, height = w_tph, bg = "lightblue") t_frame.pack() module = ("歌手1","歌手2","歌手3","歌手4","歌手5") var = tk.StringVar(value = module) lb_tf = tk.Listbox(t_frame, font = ("",15), height = 8,listvariable = var) lb_tf.place(x = 10 , y = 10) module2 = ("あいうえお","かきくけこ","さしすせそ","たちつてと","なにぬねの") var2 = tk.StringVar(value = module2) lb_tf2 = tk.Listbox(t_frame, font = ("",15), height = 8,listvariable = var2) lb_tf2.place(x = 250 , y = 10) m_frame = tk.Frame(root, width = w_width, height = w_height - w_tph, bg = "gray") m_frame.pack() C_lbl = [] K_lbl = [] for i in range(40): C_lbl.append([]) K_lbl.append([]) for j in range(16): C_lbl[i].append("") K_lbl[i].append("") C_lbl[i][j] = tk.Label(m_frame, text = "", bg = "lightblue", width = 4, font = ("",18),anchor=tk.W) C_lbl[i][j].place(x = 50 + 50*j, y = 100+i*60) K_lbl[i][j] = tk.Label(m_frame, text = "", bg = "lightblue", width = 20, font = ("",11),anchor=tk.W) K_lbl[i][j].place(x = 50 + 50*j, y = 130+i*60) openSongData() root.mainloop() |