0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PythonのTkinterで計算ツールを作ってみた!

Posted at

概要

今回は以前作れずじまいに終わった計算ツールを作成することに成功しました!
プログラムの可読性など、問題は多々ありますが、何とか作り上げることが出来ました。

ソースコード

こちらがソースコードになります。

keisan.py
import tkinter as tk

def Calculation():
    val_1=int(num_area_1.get())
    val_2=int(num_area_2.get())
    mark=mark_area.get()
    if mark=='+':
        answer=val_1+val_2
    elif mark=='-':
        answer=val_1-val_2
    elif mark=='*':
        answer=val_1*val_2
    elif mark=='/':
        answer=val_1/val_2
    elif mark=='//':
        answer=val_1//val_2
    elif mark=='%':
        answer=val_1%val_2
    elif mark=='**':
        answer=val_1**val_2
    answer_ent.delete(0,tk.END)
    answer_ent.insert(0,answer)

root=tk.Tk()

root.title(u'計算ツール カルキューレ')

root.minsize(600,580)
root.option_add("*font",["MS Pゴシック",20])

canvas=tk.Canvas(bg="#22ff22",width=700,height=540)
canvas.place(x=0,y=0)

label1=tk.Label(bg="#22ff22",text='1つ目')
label1.place(x=30,y=50)

num_area_1=tk.Entry(width=12,bd=5)
num_area_1.place(x=180,y=50)

mark_label=tk.Label(bg="#22ff22",text='算術記号')
mark_label.place(x=30,y=150)

mark_area=tk.Entry(master=root,width=12,bd=5)
mark_area.place(x=180,y=150)

label2=tk.Label(bg="#22ff22",text='2つ目')
label2.place(x=30,y=250)

num_area_2=tk.Entry(master=root,width=12,bd=5)
num_area_2.place(x=180,y=250)

ans_label=tk.Label(bg="#22ff22",text='結果')
ans_label.place(x=30,y=350)

answer_btn=tk.Button(master=root,text='答え',command=Calculation)
answer_btn.place(x=400,y=350)

answer_ent=tk.Entry(master=root,width=12,bd=5)
answer_ent.place(x=180,y=350)

text_label=tk.Label(master=root,bg="#22ff22",text='GUIDE\n//:剰余なし割り算、%:剰余、**:累乗')
text_label.place(x=20,y=450)

root.mainloop()

表示例

スクリーンショット 2025-02-23 074635.png

今後の課題

まだこのプログラムは完璧なものかと言えると、決してそうとは言い難いものかと思います。
今後はより可読性やクラス・インスタンスの使用なども検討したいところです。

0
0
2

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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?