Â
ããã°ã©ãã³ã°åå¿è ã§ãèªå¨ã«ç·¨éã§ããã«ã³ã¿ã³ãªæ¹æ³ã¯ï¼
GUIã§è¦ããããã³ããã§ä½¿ããPythonã®ãµã³ãã«ã³ã¼ãã¨ãè½ã¡ã¦ãªãï¼
Â
ãããªçåã«ãçããã¾ãã
Â
å½ããã°ã«ãç«ã¡å¯ãé ãã¾ãã¦ããããã¨ããããã¾ãï¼m(_ _)m
ããè¦ãã¦å®ã¯ã飽ãæ§ã§éã¨ã³ã¸ãã¢ã®ãããã¦Pythonå¦ç¿ãã¯ããã¦5ã«æç®ã«çªå ¥ãããã¨ã«æ°ä»ãã赤å 馬ãããã(@sekitoba1007)ã§ãã
Â
ç¡æã§ä½¿ããPythonã¯ããã°ã©ãã³ã°åå¿è ã«ãæ¯è¼çãããããããAIã ãã§ãªãå¹ åºãå©ç¨ã§ããã®ã§æ¥åå¹çã¢ããã«ã便å©ã§äººæ°ãããã¾ãããï¼
Â
ãã½ã³ã³ãæ¥é ãã使ã£ã¦ãã人ã¯ãä½æ°ãªãç¹°ãè¿ãã¦ããæ©æ¢°çãªä½æ¥ãå¤ãã¯ãã
Â
ãã¡ã¤ã«ããã©ã«ãããã¡ãã¡æ¢ããããã¡ãã¡ã¯ãªãã¯ãã¦èµ·åããããããä½æ¥ã¯ããã¾ãå¹ççã¨ã¯è¨ãã¾ããã
Â
ããããªãã¨ãã§ããããã°ã©ãã³ã°è¨èªã§ããPythonãªããExcelãèªã¿è¾¼ã¿ãªã³ã¯ã辿ã£ã¦ãµã¤ããéãããããã使ãã¢ããªãèµ·åããããããã¨ãã§ãã¾ãã
Â
ããã§æãã¤ããã®ãã使ç¨ããé »åº¦ã®é«ãã¢ããªããµã¤ãããExcelã§ç·¨éããã ãã§ä½¿ãããªã³ã¯ã®ä¸è¦§ããä½ãã¢ã¤ãã¢ã
Â
â ããã°ã©ãã³ã°ã®ã¹ãã«ããªã人ãã¡ã§ãç°¡åã«ä½¿ãã
â æ°ä»ããã¨ãã«ããã¤ã§ããµãã¨è¿½å ã»åé¤ãªã©ç·¨éãããã
Â
ä»åã¯ãããã¹ãç·¨éããã ãã§èª°ã§ãã¹ã°ã«ä½¿ãããµã³ãã«ã³ã¼ãããç¨æãã¦ããã¾ããã®ã§ããã²æè¬ãã¦è©¦ãã¦ã¿ã¦ãã ããã
Â
Â
ç®æ¬¡
- ãã³ããOKãPythonã§Excelãèªã¿è¾¼ã¿ããã ãã®ãµã³ãã«ã³ã¼ã
- Pythonã§èªã¿è¾¼ã¿ããExcelãã¡ã¤ã«
- æ¹åãé²ãï¼èªã¿è¾¼ã¿å¯¾è±¡ã®ã³ã
- ãã¾ã¨ããPythonã§Excelãèªã¿è¾¼ã¿ããã ãã§ã§ããæ¥åå¹çUPè¡
Â
Â
Â
ãã³ããOKãPythonã§Excelãèªã¿è¾¼ã¿ããã ãã®ãµã³ãã«ã³ã¼ã
Â
ããã°Ãããã°ã©ãã³ã°ã®äºåæµã§çèªð
â 赤å 馬ï¼ããã¨ã°ï¼@ããããããããããã¬ã¼ (@sekitoba1007) June 25, 2023
Pythonå¦ç¿ã®ä¸ç°ã§èªä½ããããã°ç¨ã¡ãã¥ã¼ç»é¢ã工夫ããã®ã¯ãExcelã®ãªã¹ããèªã¿è¾¼ãã§ãããã®ã§ãä¸åº¦ä½ã£ããã³ã¼ããç·¨éããå¿ è¦ããªããã¨ãExcelããµãã¨ç·¨éãã¦èªã¿ç´ãã°æ´æ°å®äºã使ç¨é »åº¦ã®é«ãä½æ¥ãéãã¦ä½æ¥å¹çã¢ãããçã⤴#ããã° pic.twitter.com/AKE6fccqy8
Â
ãPySimpleGUIãã使ã£ãPythonã³ã¼ãã¯ã以ä¸ã®ã¨ããã§ãã
import PySimpleGUI as sg
import pandas as pd
import subprocess
import os
import webbrowser
import threading
# Excelãã¡ã¤ã«ãèªã¿è¾¼ã
excel_file_path = r"program_list.xlsx" # ããã«ãã¹ãè¨è¼
df = pd.read_excel(excel_file_path)
# "TABå称"ã"PGå称"ã"PGãªã³ã¯"ã®åã®å¤ãåå¾
tab_names = df["TABå称"].unique() # éè¤ãæé¤ããTABå称ã®ãªã¹ã
pg_names = df["PGå称"].tolist() # PGå称ã®ãªã¹ã
pg_links = df["PGãªã³ã¯"].tolist() # PGãªã³ã¯ã®ãªã¹ã
# ã¿ãã¬ã¤ã¢ã¦ãã®ä½æ
tab_layouts = []
for tab_name in tab_names:
# é¸æãããTABã«å¿ãã¦å¯¾å¿ããPGå称ã¨PGãªã³ã¯ãåå¾
selected_pg_names = [pg_name for pg_name, tab in zip(pg_names, df["TABå称"]) if tab == tab_name]
selected_pg_links = [pg_link for pg_link, tab in zip(pg_links, df["TABå称"]) if tab == tab_name]
# ã¿ãã®ã¬ã¤ã¢ã¦ã
tab_rows = []
for pg_name, pg_link in zip(selected_pg_names, selected_pg_links):
# ãå®è¡ããã¿ã³ã®ã¯ãªãã¯æã®ã³ã¼ã«ããã¯é¢æ°
def run_program(pg_link):
subprocess.run(pg_link, shell=True) # PGãªã³ã¯ãå®è¡ãã
# PGå称ã¨ãå®è¡ããã¿ã³ãå«ãã¬ã¤ã¢ã¦ã
row = [sg.Button("å®è¡", key=pg_link), sg.Text(pg_name)]
tab_rows.append(row)
tab_layout = tab_rows
tab_layouts.append(tab_layout)
# ã¿ãã°ã«ã¼ãã®ä½æ
tab_group_layout = [[sg.Tab(tab_name, tab_layouts[i]) for i, tab_name in enumerate(tab_names)]]
# å
¨ä½ã®ã¬ã¤ã¢ã¦ã
layout = [[sg.TabGroup(tab_group_layout)], [sg.Button("çµäº")]]
# ã¦ã£ã³ãã¦ãä½æ
window = sg.Window("ããã°ã©ã ä¸è¦§", layout)
# ãå®è¡ããã¿ã³ã®ã¯ãªãã¯æã®ã³ã¼ã«ããã¯é¢æ°
def run_program(pg_link):
subprocess.run(pg_link, shell=True) # PGãªã³ã¯ãå®è¡ãã
def open_link(link):
if link.startswith("http://") or link.startswith("https://"):
webbrowser.open(link) # URLãéã
elif os.path.isdir(link):
os.startfile(link) # ãã©ã«ããéã
else:
subprocess.run(link, shell=True) # ãã¡ã¤ã«ãå®è¡ãã
# ãå®è¡ããã¿ã³ã®ã¯ãªãã¯æã®ã¤ãã³ããã³ãã©
def handle_button_click(event):
if event in pg_links:
index = pg_links.index(event) # ã¯ãªãã¯ããããã¿ã³ã«å¯¾å¿ããPGãªã³ã¯ã®ã¤ã³ããã¯ã¹ãåå¾
pg_link = pg_links[index]
# ã¹ã¬ããã使ç¨ãã¦ããã°ã©ã ãéåæã«å®è¡ãã
threading.Thread(target=open_link, args=(pg_link,)).start()
# ã¤ãã³ãã«ã¼ããéå§
while True:
event, values = window.read()
# ã¦ã£ã³ãã¦ãéããããå ´åãçµäºãã¿ã³ãæ¼ãããå ´åã¯ã«ã¼ããçµäº
if event == sg.WINDOW_CLOSED or event == "çµäº":
break
# ãå®è¡ããã¿ã³ãã¯ãªãã¯ãããå ´å
handle_button_click(event)
# ã¦ã£ã³ãã¦ãéãã¦çµäº
window.close()
Â
ä¸é¨ã®ãexcel_file_path = r"program_list.xlsx" # ããã«ãã¹ãè¨è¼ãã®é¨åã«ãå®éã«ä½¿ãExcelãã¡ã¤ã«ã®ãã¹ãæå®ããã°å®æã§ãã
Â
Â
ãPySimpleGUIãã©ã¤ãã©ãªã®ã¤ã³ã¹ãã¼ã«(å¿ è¦ã«å¿ãã¦)
Â
PySimpleGUIã®ã¤ã³ã¹ãã¼ã«ã«å¿ è¦ãªã³ã¼ãã§ãã
pip install PySimpleGUI
Â
Â
ãpandasãã©ã¤ãã©ãªã®ã¤ã³ã¹ãã¼ã«(å¿ è¦ã«å¿ãã¦)
Â
pandasã®ã¤ã³ã¹ãã¼ã«ã«å¿ è¦ãªã³ã¼ãã§ãã
pip install pandas
Â
Â
Â
Â
Pythonã§èªã¿è¾¼ã¿ããExcelãã¡ã¤ã«
Â
ãTABå称ããPGå称ããPGãªã³ã¯ãã¨ãã3ã¤ã®åãä½ãã¾ãã
ãTABå称ãã¯ãã¡ãã¥ã¼ç»é¢ã®ã¿ãã«åæ ãããå称ãè¨å ¥ãã¦ãã ãããä½æ¥ãã¸ã£ã³ã«ãã¨ã«èªåã§ããããããå称ã«ããã®ããªã¹ã¹ã¡ã§ãã
Â
ãPGå称ãã¯ãåã¿ããã¨ã«ç¾ åãããããã°ã©ã ã®å称ãè¨å ¥ãã¦ãã ããã
Â
ãPGãªã³ã¯ãã¯ããªã³ã¯ããããã¹ãè¨å ¥ãã¦ãã ãããã»ãã®ããã°ã©ã ãèµ·åãããããPCå ã®ãã©ã«ãããã¡ã¤ã«ãéãããããURLãè¨å ¥ãã¦ããã°ãã使ããµã¤ããéããããããã¨ãã§ãã¡ããã¾ãã
Â
ä½æããExcelãã¡ã¤ã«ãä»»æã®ãã©ã«ãã«æ ¼ç´ãããããã®ãã¹ãåè¿°ããã¨ããã³ã¼ãã«æ¸ãæãã¦æå®ãã¦ãã ããã
Â
Â
ãã¹ã®ç°¡åãªåãè¾¼ã¿æ¹
ãShiftããæ¼ããªãããã¡ã¤ã«ãå³ã¯ãªãã¯ããã¨ãããã¹ã®ã³ãã¼ããç°¡åã«ã§ãã¾ãã®ã§ãå å¯ã«ã
Â
Â
æ¹åãé²ãï¼èªã¿è¾¼ã¿å¯¾è±¡ã®ã³ã
Â
å®éã«èªåã§ä½¿ã£ã¦ã¿ã¦ããã£ããã¤ã³ãã¨ãã¦ãèªã¿è¾¼ã¿å¯¾è±¡ã«ã¯ãExcelã®èªè¾¼ãªã¹ãèªèº«ã¸ã®ãªã³ã¯ãè¨ãã¦ãããã¨ããè¶ ãªã¹ã¹ã¡ã§ãã
Â
ãªããªããæãã¤ããã¨ãã«ãµãã¨ç·¨éã§ããã¨å¹çã¢ãããã©ãã©ãé²ãããï¼
Â
ã²ããããã¨ããã¢ã¤ãã¢ã試ãããã¨ããããã«Excelã®ãªã¹ãç·¨éãã§ããã¨æ¹åãç¹°ãè¿ããã¦ããã¦ãã¦ããæ¢ã¾ããªæ¥½ãããªã£ã¦ããã¯ãã§ããã
Â
Â
Â
Â
ãã¾ã¨ããPythonã§Excelãèªã¿è¾¼ã¿ããã ãã§ã§ããæ¥åå¹çUPè¡
Â
ä»åã¯ãæ¥åå¹çã¢ããè¡ã¨ãã¦ãéã¨ã³ã¸ãã¢ã§ãæ´»ç¨ã»ç·¨éã§ããExcelã使ã£ãPythonã³ã¼ããã解説ãã¾ããã
Â
ä½ããä½ã¾ã§ç¤¾å SEã«ä¸¸æãããã®ã§ã¯ãªããExcelãã使ããã°èªåã§ã«ã¹ã¿ãã¤ãºã§ããæ¹æ³ã¯ç¹å¥ãªããã°ã©ãã³ã°ã®ã¹ãã«ãä¸è¦ãªããéã¨ã³ã¸ãã¢ã®ITãªãã©ã·ã¼ãè²ã¦ãæå³ã§ãæå¹ãªã¯ãï¼
Â
çµã¿åãããªã©ã¢ã¤ãã¢ãã ãã§å®ç¨æ§ãæ¡å¼µæ§ã¯ç¡éã«åºããã¯ããªã®ã§ããã²ãã£ã¦ã¿ã¦ãã ãã¾ãã
Â
Â
Â
æå¾ã¾ã§ãèªã¿ããã ãããããã¨ããããã¾ããã
Â
Â
Â