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?

[備忘録]電卓の開発

Posted at

はじめに

初めまして。独学で、プログラミングの学習を行っているえむしたと申します。
今回は、PythonとTKinterを使った電卓開発の備忘録を記録していきます。
拙い記事ではありますが、読んでいただけると幸いです。

使用ツール

言語:Python
FW:TKinter
バージョン管理: Git, GitHub
開発ツール: VScode

要件

・四則演算
・入力した数字をリスト管理し、足し算、掛け算を1つのボタンで合計する

メインウィンドウの設計

メインウィンドウ
root = tk.Tk()  # Tkinterのウィンドウを作成
root.title("計算機")  # ウィンドウのタイトルを設定
root.geometry("700x500")  # ウィンドウサイズを設定
ライブラリ
import tkinter as tk #asを利用し、tkで定義できるように指定

まずはアプリを起動した際の表示を作成しました。
今回は、ボタン数が通常の電卓より多いのでウィンドウサイズを大きめに設定しました。

計算結果エリアの作成

計算結果エリア
#計算結果エリア
display = tk.Label(root, text="0", font=("Arial", 24),anchor="e", bg="white", relief="sunken") 
display.pack(fill="both", padx=10, pady=10)

エリアに、初期値"0"を表示する為に、text=0 と指定しています。
また、sunkenを使い、ウィジェット自体が少しへこむように見せ、より市販の電卓っぽさを出しています

ボタン配置のフレームを作成

ボタン配置フレーム
# 計算機のボタン配置用フレームを作成
button_frame = tk.Frame(root)
button_frame.pack()

tk.Frame(root)を利用し、メインウィンドウに対して、複数のウィジェットをグループ化するようにしています

まとめ

今回は、アプリの大枠を作成しました。
全てを1つの記事にまとめると長くなりすぎるので、細かく書いていこうと思います。
次回は、四則演算のボタン配置を書いていきます。
ありがとうございました。

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?