LoginSignup
1
0

More than 1 year has passed since last update.

tkinterで残業代計算

Last updated at Posted at 2022-12-01

初めに

この記事は、ニフティグループ Advent Calendar 2022 6日目の記事です。

残業代の計算方法を知らなかったので、
デスクトップアプリを作成しながら学ぶ
※Tkinterの書き方は他の方の記事があるので触れません

環境

MAC bookair M1
python3.1

残業代の計算方法

下記を参考にしました。
https://www.obc.co.jp/360/list/post247

残業時間は
1時間あたりの賃金(時給)×1.25(割増率)×残業時間」で算出します。

1時間当たりの賃金は、「月給÷所定労働時間」で求めます。
※月給にはボーナスなどは含まれません

Screenshot 2022-12-06_14-36-24-601.png

実行イメージ

値を入力し、実行ボタンを押して実行

上記を踏まえて、

月収と所定労働時間と今月の残業時間と割増率を入力し、判定ボタンを押して残業代計算をするデスクトップアプリ作成
画像の場合
手当等を抜いた月収を28万円、一日の所定労働時間8時間x月20日労働で160時間
今月の残業時間20時間、深夜残業はしていないので割増率を1.25
として計算

Screenshot 2022-12-06_14-25-32-742.png

code

import tkinter as tk

#1時間あたりの賃金 月給 ÷ 月平均所定労働時間
def calcwages(fee, avrworktime):
    return fee / avrworktime


root = tk.Tk()
root.title('残業代チェック')
root.geometry('400x400')

#Labelウィジェット
label_1 = tk.Label(root, text='収入(基本給)')
label_2 = tk.Label(root, text='円')
label_3 = tk.Label(root, text='所定労働時間')
label_4 = tk.Label(root, text='h')
label_5 = tk.Label(root, text='1時間あたりの賃金を計算')
label_6 = tk.Label(root, text='計算結果')
label_7 = tk.Label(root, text='今月の残業時間')
label_8 = tk.Label(root, text='割増率(深夜だったら1.5など)')

#entryウィジェット
fee = tk.Entry(width=6)
avrworktime = tk.Entry(width=5)
workovertime = tk.Entry(width=5)
raiserate = tk.Entry(width=5)

#Buttonのハンドラ関数
def judgement():
    f = int(fee.get())
    h = int(avrworktime.get()) #所定労働時間
    t = int(workovertime.get()) #残業時間
    k = float(raiserate.get()) #割増率係数
    s = calcwages(f, h)
    label_5['text'] = '1時間あたりの賃金:' + str(s)   #str組み込み関数で計算結果を文字列にして返す
    label_6['text'] = '残業代' + str(s * t * k)

#Buttonウィジェットの作成
button = tk.Button(root, text='判定', command=judgement)

root.columnconfigure(0, weight=1)
root.columnconfigure(1, weight=1)
root.columnconfigure(2, weight=1)
root.rowconfigure(0, weight=1)
root.rowconfigure(1, weight=1)
root.rowconfigure(2, weight=1)
root.rowconfigure(3, weight=1)

#grid関数でウィジェットの配置
label_1.grid(column=0, row=0, sticky=tk.E)
fee.grid(column=1, row=0)
label_2.grid(column=2, row=0, sticky=tk.W)
label_3.grid(column=0, row=1, sticky=tk.E)
avrworktime.grid(column=1, row=1)
workovertime.grid(column=1, row=2)
raiserate.grid(column=1, row=3)
label_4.grid(column=2, row=1, sticky=tk.W)
button.grid(column=3, row=2, columnspan=5)
label_5.grid(column=0, row=4, columnspan=3)
label_6.grid(column=0, row=5, columnspan=4)
label_7.grid(column=0, row=2)
label_8.grid(column=0, row=3)
root.mainloop()

明日は、@IWS_113(https://qiita.com/IWS_113)さんの[NIFTY Tech Talkのこと]です。

1
0
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
1
0