0
1

pythonのライブラリー使ってポモドーロツールを作る

Posted at

概要

pythonのライブラリー使ってポモドーロツールを作ります
・PySimpleGUI
・pygame

アナコンダをインストール

pythonを使うのにanacondaをダウンロードしてインストールします
https://www.anaconda.com/download

環境変数を編集を設定する

windowsメニューで「環境変数を編集」を入力して起動
image.png

image.png
ユーザー環境変数のPathにanacondaのインストールした場所を設定する

Path=C:\work\anaconda3

音をダウンロードする

魔王魂からダウンロードします。音の利用は魔王魂のルールに従ってください
https://maoudamashii.jokersounds.com/archives/se_maoudamashii_onepoint30.html

必要なライブラリーをインストール

「anaconda prompt」を起動して、コマンド実行してインストール

image.png

# pip3 install PySimpleGUI
# pip3 install pygame

実行

任意の作業フォルダーに「pomo.py」のファイルを作成
※先ほどダウンロードした音も一緒のフォルダーに入れてください

作成したpythonのファイルの場所に移動する

import PySimpleGUI as sg
import pygame.mixer
import time
from datetime import datetime, date, timedelta
 
layout = [
   [sg.Text('ポモドーロ')],
   [sg.Text('時間', size=(15,1)),sg.Text('25:00:00', key="time", size=(15,1))],
   [sg.Text('間隔', size=(15,1)), sg.InputText('25')],
   [sg.Text('休憩', size=(15,1)), sg.InputText('5')],
   [sg.Submit(button_text='開始'),sg.Submit(button_text='一時停止'),sg.Submit(button_text='停止')]]
 
pygame.mixer.init(frequency = 44100)
pygame.mixer.music.load("maou_se_onepoint30.mp3")
 
dtAdd = ''
startFlg = 0
status = 2
win = sg.Window('ポモドーロ', layout)

while True:
   event, values = win.read(timeout=1)
   if dtAdd != '':
     if startFlg == 1:
       win["time"].update((dtAdd - datetime.now()))
       minuteAdd = dtAdd.minute
       if dtAdd.hour > datetime.now().hour:
         minuteAdd += 60
 
       if ((minuteAdd - datetime.now().minute) <= 0 and (dtAdd.second - datetime.now().second) <= 0) :
           if status == 1:
               dtAdd = datetime.now() + timedelta(minutes=int(values[0]))
               status = 2
           elif status == 2:
               dtAdd = datetime.now() + timedelta(minutes=int(values[1]))
               status = 1
           
           pygame.mixer.music.play(3)
   
   if event is None: break
   if event == '開始':
     dtAdd = datetime.now() + timedelta(minutes=int(values[0]))
     startFlg = 1
   elif event == '一時停止':
     startFlg = 1 if startFlg == 0 else 0
   elif event == '停止':
     startFlg = 0
     status = 2
     pygame.mixer.music.play(1)
     time.sleep(1)
     pygame.mixer.music.stop()

実行すると下記の画面が表示されます

# python pomo.py

image.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1