3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Python】勤怠入力アプリ作成

Posted at

勤怠入力のデスクトップアプリを簡易的に作成しました。
随時、更新をしていきます。

入力前

image.png

入力後

image.png

ソース

import tkinter
from datetime import datetime

def days_func():
    '''日付を取得しラベルにセットする。'''
    import datetime
    t_delta = datetime.timedelta(hours=9)
    JST = datetime.timezone(t_delta, 'JST')
    now = datetime.datetime.now(JST)
    d_week = {'Sun':'', 'Mon':'', 'Tue':'', 'Wed':'', 'Thu':'', 'Fri':'', 'Sat':''}
    key = now.strftime('%a') # 曜日を取得
    w = d_week[key] # 辞書で値を取得。
    days_today = now.date().strftime('%Y/%m/%d') # 指定したformatに従って日時の文字列を返す。
    lbl_days = tkinter.Label(text=str(days_today + str(f' ({w})')))
    lbl_days.place(x=10, y=20)

def btn_click():
    total_value.delete(0, tkinter.END) 
    start = start_value.get()
    last = last_value.get()
    rest = rest_value.get()
    FMT = '%H:%M:%S'
    tdelta = datetime.strptime(last, FMT) - datetime.strptime(start, FMT)
    tdelta_cgange = str(tdelta)
    tdelta_1 = datetime.strptime(tdelta_cgange, FMT) - datetime.strptime(rest, FMT)
    total_value.insert(0, str(tdelta_1))

def btn_clear():
    """
    テキストに入力された値を削除
    """
    start_value.delete(0, tkinter.END) # 削除の処理
    last_value.delete(0, tkinter.END)
    rest_value.delete(0, tkinter.END)
    total_value.delete(0, tkinter.END)

# 画面作成
tki = tkinter.Tk()
tki.geometry('450x350')
tki.title('勤怠入力')
tki.configure(bg='SpringGreen2')
# メッセージを表示
lbl_massage = tkinter.Label(text='勤務時間を入力して下さい。')
lbl_massage.place(x=150, y=60)

days_func()

start_lbl = tkinter.Label(text='出勤時間')
start_lbl.place(x=50, y=100)
last_lbl = tkinter.Label(text='退勤時間')
last_lbl.place(x=50, y=130)
rest_lbl = tkinter.Label(text='休憩時間')
rest_lbl.place(x=50, y=160)
total_lbl = tkinter.Label(text='労働時間')
total_lbl.place(x=50, y=190)

# テキストボックス
start_value = tkinter.Entry(width=30)
start_value.place(x=140, y=100)
last_value = tkinter.Entry(width=30)
last_value.place(x=140, y=130)
rest_value = tkinter.Entry(width=30)
rest_value.place(x=140, y=160)
total_value = tkinter.Entry(width=30)
total_value.place(x=140, y=190)

# ボタン
btn = tkinter.Button(tki, text='合    計', font=("MSゴシック", "10", "bold"), fg="red", relief= "ridge",command=btn_click)
btn.place(x=170, y=220)
btn = tkinter.Button(tki, text='ク リ ア', font=("MSゴシック", "10", "bold"), fg="red", relief= "ridge", command=btn_clear)
btn.place(x=170, y=260)

tki.mainloop() # アプリを起動
3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?