0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

📘 VSCode + Python + tkinter で英単語アプリを作ってみた!

Posted at

はじめに

pythonの勉強のために、Pythonとtkinterを使って簡単な英単語アプリを作ってみました。
GUIで操作できるので、毎日の学習にも使えそうです!


🛠️ 使用した技術

  • Python 3.x
  • tkinter(標準GUIライブラリ)
  • VS Code(開発環境)

🎯 アプリの概要

  • ランダムに英単語を表示
  • 「意味を表示」ボタンで意味を表示
  • 「次の単語」ボタンで次の単語へ

以下のようなシンプルなUIです👇

スクリーンショット 2025-09-08 0.43.32.png


💻 サンプルコード

import tkinter as tk
import random

# 単語データ(実際はCSVなどから読み込むのも◎)
words = [
    {"word": "apple", "meaning": "りんご"},
    {"word": "book", "meaning": ""},
    {"word": "cat", "meaning": ""},
]

# ランダムに単語を選ぶ関数
def show_word():
    global current_word
    current_word = random.choice(words)
    word_label.config(text=current_word["word"])
    meaning_label.config(text="")

# 意味を表示する関数
def show_meaning():
    meaning_label.config(text=current_word["meaning"])

# ウィンドウ作成
root = tk.Tk()
root.title("英単語アプリ")
root.geometry("300x200")

# 単語表示ラベル
word_label = tk.Label(root, text="", font=("Arial", 24))
word_label.pack(pady=20)

# 意味表示ラベル
meaning_label = tk.Label(root, text="", font=("Arial", 18))
meaning_label.pack()

# ボタン類
btn_show = tk.Button(root, text="意味を表示", command=show_meaning)
btn_show.pack(pady=5)

btn_next = tk.Button(root, text="次の単語", command=show_word)
btn_next.pack()

# 最初の単語を表示
show_word()

# メインループ開始
root.mainloop()

🧾 コードの解説

📦 単語データの定義

words = [
    {"word": "apple", "meaning": "りんご"},
    {"word": "book", "meaning": ""},
    {"word": "cat", "meaning": ""},
]
  • 辞書型(dict)で「英単語」と「意味」を管理
  • 今回はリストにハードコーディングしていますが、CSVやJSONから読み込むことも可能です

🎲 ランダムに単語を選ぶ関数

def show_word():
    global current_word
    current_word = random.choice(words)
    word_label.config(text=current_word["word"])
    meaning_label.config(text="")
  • random.choice() で単語リストから1つ選びます
  • 最初は意味を「?」にして隠しています

🪄 意味を表示する関数

def show_meaning():
    meaning_label.config(text=current_word["meaning"])
  • ボタンを押すと、選ばれた単語の意味を表示します

🖼️ GUI の構成

root = tk.Tk()
root.title("英単語アプリ")
root.geometry("300x200")
  • ウィンドウの基本設定です

🧩 ウィジェット(部品)の作成

word_label = tk.Label(root, ...)
meaning_label = tk.Label(root, ...)
btn_show = tk.Button(root, ...)
btn_next = tk.Button(root, ...)
  • Label で単語と意味を表示
  • Button で操作します

🔁 最初の単語を表示 & イベントループ開始

show_word()
root.mainloop()
  • アプリ起動時に最初の単語を表示
  • mainloop() でGUIを起動します

🚀 改良アイデア

この記事では基本機能だけですが、以下のような拡張も可能です:

  • 単語をCSVファイルから読み込む
  • 正解・不正解ボタンを付けてスコアを記録
  • 出題順をシャッフルする
  • 見た目をおしゃれに改善する(フォント、色、アイコンなど)

📚 まとめ

  • Pythonのtkinterを使えば、簡単にGUIアプリが作れる!
  • 英語学習アプリを自作すれば、学習効率もアップ!
  • シンプルな構成なので、初心者にもおすすめのプロジェクトです

📝 おわりに

最後まで読んでいただきありがとうございました!
コメント・LGTM・フォロー大歓迎です😊

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?