Pythonã§ç°¡åã«GUIã¢ããªãä½ããç°å¢ã¨ãã¦ãPySimpleGUIããã¼ã¸ã§ã³5ãããåç¨å©ç¨ã®å ´åã¯æåã¨ãªãã¾ããã
å人ã使ãå ´åã¯ãããã¾ã§éããç¡åã§ä½¿ããã¨ã®ãã¨ã§ãããã©ã¤ãã©ãªã使ãåããã®ã¯å¤§å¤ãªã®ã§ãPySimpleGUIã®APIã®äºææ§ãæã¤ãTkEasyGUIãã«ä¹ãæãããã¨ã«ãã¾ãï¼ã¨ããè¨äºã§ãã
ä»åã¯ãTkEasyGUIã®ç´¹ä»ã¨ç°¡åãªä½¿ãæ¹ãç´¹ä»ãããã¨æãã¾ãã
ããã§ã¯ããã£ã¦ããã¾ãï¼
ã¯ããã«
åç´ãªGUIã¢ããªãä½ãã¨ãã«ã大å¤éå®ãã¦ããPySimpleGUIãæååãããã¨ãããã¨ã§ã大å¤æ®å¿µãªãã¥ã¼ã¹ã§ããã
ã§ãããPySimpleGUIäºæã®TkEasyGUIã使ã£ã¦ã¿ãã¨ããï¼åãããï¼ã¨ããããããï¼ä»ã®ã¨ããï¼ä½¿ãåæãã»ã¨ãã©å¤ãããªãç´ æ´ãããã©ã¤ãã©ãªã§ãã
PySimpleGUIã使ãã¨ãã¯ã以ä¸ã®ããã«ãPySimpleGUIãã¤ã³ãã¼ããã¦ããæ¸ãã¦ããã¾ãã
import PySimpleGUI as sg
ä»ã¾ã§æ¸ãã¦ããã®ãã以ä¸ã«æ¸ãç´ããã ãã§åãã¾ããï¼ç¬ï¼
import TkEasyGUI as sg
ã¨ããããã§ãAPIã¬ãã«ã§äºææ§ãããã¾ãï¼
â»2024/4/27追è¨ï¼TkEasyGUIã使ã£ãGUIã¢ããªãå
¬éãã¾ãããè¯ãã£ããè¦ã¦ãã ãã
daisuke20240310.hatenablog.com
TkEasyGUIã®ã¤ã³ã¹ãã¼ã«
以ä¸ã¯ãTkEasyGUIã®éçºè
ï¼æ¥æ¬ã®æ¹ã§ãï¼ã®æ¹ã®è¨äºã§ãã
note.com
ãã®è¨äºã«ãTkEasyGUI ã®ã¤ã³ã¹ãã¼ã«æ¹æ³ã¨ãç°¡åãªä½¿ãæ¹ãæ¸ããã¦ãã¾ãããæ¸ãå
容ããªããªãã¾ããï¼ç¬ï¼
ä¸å¿ãã¤ã³ã¹ãã¼ã«æ¹æ³ã§ãã
$ pip install TkEasyGUI
TkEasyGUIã®ç°¡åãªä½¿ãæ¹
次ã¯ãç°¡åãªä½¿ãæ¹ã¨èª¬æã§ãã
ç§ããã¤ã使ã£ã¦ãã¯ãªãããã¼ãã使ãã¢ããªãæ¸ãã¦ã¿ã¾ããã
import TkEasyGUI as eg
import pyperclip
TITLE = "show clip_simple.py"
layout = [ [eg.Text("", key='text')] ]
window = eg.Window( TITLE, layout, size=(250, 40) )
getdata = pyperclip.paste()
getdata_old = ""
while True:
event, values = window.read( timeout=1000 )
if event != "__TIMEOUT__" and event != "-TIMEOUT-":
if event == eg.WIN_CLOSED:
break
getdata = pyperclip.paste()
if getdata == getdata_old:
continue
else:
window['text'].update( getdata )
getdata_old = getdata
window.close()
ç°¡åã«ã½ã¼ã¹ã³ã¼ãã説æãã¾ãã
- importã®1ã¤ç®ã¯ãTkEasyGUIã§ã
- importã®2ã¤ç®ã¯ãã¯ãªãããã¼ãã®å
容ãåå¾ã§ããã©ã¤ãã©ãªã§ã
- TITLEã¯ãã¦ã£ã³ãã¦ã®ã¿ã¤ãã«ã«è¡¨ç¤ºããæååã§ã
- layoutã«ä»£å
¥ãã¦ããã¨ããã¯ããªã¹ãã§ããããã®å½¢å¼ã§ãGUIã®ã¦ã£ã³ãã¦ã表ç¾ã§ãã¾ãï¼ä»åã¯åç´ãªã¦ã£ã³ãã¦ãªã®ã§ãããã¹ããªãã¸ã§ã¯ãã ããé
ç½®ãã¦ãã¾ãï¼
- eg.window()ã§ã¦ã£ã³ãã¦ãä½æãã¾ãï¼sizeã§ã¦ã£ã³ãã¦ã®ãµã¤ãºãæå®ã§ãã¾ãï¼
- pyperclip.paste()ã§ãç¾å¨ã®ã¯ãªãããã¼ãã®å
容ãåå¾ãã¦ãã¾ã
- getdata_oldã«ã¯ã1ã¤åã«ã¯ãªãããã¼ãã«å
¥ããå
容ãæ ¼ç´ãã¾ãï¼åæå¤ã¯ç©ºã«ãã¦ããã¾ãï¼
- ãã以éã¯ç¡éã«ã¼ãã§ãÃãã¿ã³ãæ¼ãããã¾ã§ãåä½ãç¶ãã¾ã
- window.read( timeout=1000 )ã§ãã¦ã£ã³ãã¦ãåå¾ãã¾ããã¿ã¤ã ã¢ã¦ãã1ç§ã«è¨å®ãã¦ãã¾ãï¼ã¿ã¤ã ã¢ã¦ããè¨å®ããªãã¨ã¤ãã³ããèµ·ããã¾ã§å¾
ã¤ãã¨ã«ãªãã¾ãããã¯ãªãããã¼ãã«å
容ãå
¥ã£ã¦ãã¤ãã³ãã¯çºçããªãã®ã§ã1ç§ãã¨ã«ãã¼ãªã³ã°ãã¦ãã¾ãï¼
- ã¾ããã¯ãªãããã¼ãã®å
容ãåå¾ãã¾ãã1ã¤åã®å
容ã¨åããªãã¤ãã³ãå¾
ã¡ã«æ»ãã¾ã
- ã¯ãªãããã¼ãã«æ°ããå
容ãå
¥ã£ãããã¦ã£ã³ãã¦ã«åæ ãã¾ã
- 次ã®ããã«ãgetdata_oldã«ä»åã®ã¯ãªãããã¼ãã®å
容ãå
¥ãã¦ããã¾ã
- Ããæ¼ãããã¨ã¦ã£ã³ãã¦ãã¯ãã¼ãºãã¦çµäºãã¾ã
ã§ã¯ãããã Windows10 ã® IDLE ã§å®è¡ãã¦ã¿ã¾ãã
IDLEãèµ·åãã¦ãFileâNew Fileãã¯ãªãã¯ãã¾ãã
ä¸ã®ã³ã¼ããè²¼ãä»ãã¾ãã
ã§ã¯ãå®è¡ãã¦ã¿ã¾ããRunâRun Moduleãã¯ãªãã¯ãã¾ãã
ãã¡ã¤ã«ã«ä¿åãã¦ãã ãããã®ãããªã¡ãã»ã¼ã¸ãåºãã®ã§ãé©å½ãªãã©ã«ãã«ä¿åãã¾ãã
ããã¨ã以ä¸ã®ãããªã¦ã£ã³ãã¦ãèµ·åãã¦ãç¾å¨ã®ã¯ãªãããã¼ãã®å
容ã表示ããã¦ãã¨æãã¾ãã
è¤æ°è¡ãæ³å®ãã¦ãªãã®ã§ãå¤ãªè¡¨ç¤ºã«ãªã£ã¦ããããããã¾ããã
ä½ãã®1è¡ã ãã®æç« ãã³ãã¼ãã¦ã¿ã¦ãã ããã
ä¸ã®ç»åã®ããã«ãªãã¨æãã¾ãã
ç°¡åã§ããã使ãæ¹ã¯ä»¥ä¸ã§ãã
詳細ã®ä½¿ãæ¹ã¯ãTkEasyGUIã®GitHubã®ããã¥ã¡ã³ããåç
§ããããPySimpleGUIã¨äºææ§ãé«ãã®ã§ãPySimpleGUIã®ä½¿ãæ¹ã§æ¤ç´¢ããã¨ããããåºã¦ããã®ã§ããã¡ããåç
§ãã¦ãããã¨æãã¾ãã
GitHubã¯ä»¥ä¸ã§ãã
github.com
çµããã«
ä»åã¯ãPythonã§ãç°¡åã«GUIã¢ããªãä½ãã PySimpleGUI ãåç¨å©ç¨ã¯æåã«ãªã£ãã®ã§ãPySimpleGUI ã¨äºææ§ã®é«ã TkEasyGUI ã®ç´¹ä»ã§ããã
次åã¯ããã® TkEasyGUI ã¨ãWebã¹ã¯ã¬ã¤ãã³ã°ãçµã¿åããã GUIã¢ããªãä½ã£ã¦ã¿ããã¨æãã¾ãã
ä»åã¯ä»¥ä¸ã§ãï¼
æå¾ã¾ã§ãèªã¿ããã ãããããã¨ããããã¾ããã