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?

More than 1 year has passed since last update.

tkinterでGUI作成①

Last updated at Posted at 2022-01-03

##動作環境

windows 10
python

##tkinterとは
Pythonでグラフィック表示・操作(GUI)のソフトウェアを開発するためのライブラリの一つ
https://e-words.jp/w/Tkinter.html

他にもライブラリはありますが、使いやすそうだったので、tkinterを使用しました。

##簡単な計算アプリの作成

main.py
import tkinter as tk
import tkinter.ttk as ttk

app = tk.Tk()
app.geometry("400x400")
app.title("calculator")
class func(tk.Frame):
    def calculation():
        a = float(val_a.get())
        b = float(val_b.get())
        ope = str(ope_com.get())
        if ope == "+":
            answer = a + b
        elif ope == "-":
            answer = a - b
        elif ope == "*":
            answer = a * b
        elif ope == "//":
            answer = a // b
    
        answer_ent.delete(0, tk.END)
        answer_ent.insert(0, answer)
    
#val_a
val_a = tk.Entry(app,width=4)
val_a.place(x=10, y=30)
#operator
ope_com = ttk.Combobox(state='readonly',width=2)
ope_com["values"] = ("+","-","*","//")
ope_com.place(x=50, y=30)
#val_b
val_b = tk.Entry(app,width=4)
val_b.place(x=90, y=30)
#計算ボタンの作成
btn = tk.Button(app, text="計算", command=func.calculation, height=1,width=4)
btn.place(x=130, y=30)
#answer
answer_ent = tk.Entry(app,width=10)
answer_ent.place(x=200, y=30)
app.mainloop()

##出力結果
計算がうまく出来ています。
スクリーンショット (32).png

##まとめ
今後また時間があるときにさらに機能を実装していこうと思います。

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