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

いまさら「令和何年?」って調べない

Last updated at Posted at 2025-01-05

ちょこっと業務を簡略化したい

 この記事では、ちょこっと効率化させたいことをプログラミングやツールをつかって解決していきます
ちょこっと削減した時間を、もっと人生楽しくなることに使いましょう!

今年令和何年? 何どし?

「今年令和何年?」と検索していないでしょうか
わからなくなりますよね
こんな時はこれで解決です!

python(tkinter)で解決してみた

<環境>
🖥 Mac
🐍 python 3.12.5
🏆 VSCode

※YouTube動画です。音量に気をつけてください

YouTube動画

全体コード

全体コードはこちら
python
import tkinter as tk
from tkinter import ttk
from datetime import datetime

# 干支リスト
eto_list = ["🐭子", "🐮丑", "🐯寅", "🐰卯", "🐲辰", "🐍巳", "🐴午", "🐑未", "🐒申", "🐓酉", "🐕戌", "🐖亥"]

# 情報計算関数
def calculate_info():
    try:
        year = int(year_entry.get())
        eto = eto_list[(year - 4) % 12]
        if year >= 2019:
            era = f"令和{year - 2018}"
        elif year >= 1989:
            era = f"平成{year - 1988}"
        elif year >= 1926:
            era = f"昭和{year - 1925}"
        else:
            era = "大正以前"
        today = datetime.now()
        weekday = today.strftime("%A")
        today_str = today.strftime("%Y年%m月%d日")
        result_label.config(
            text=f"🌸 {year}年は 🌸\n\n"
                 f"{eto}どし\n"
                 f"{era}\n"
                 f"③ 今日は {today_str}{weekday}"
        )
    except ValueError:
        result_label.config(text="⚠️ 正しい年を入力してください! ⚠️")

# アプリウィンドウの設定
root = tk.Tk()
root.title("🌸 年情報アプリ 🌸")
root.geometry("400x450")
root.config(bg="#fffbf0")

# タイトルラベル
title_label = tk.Label(
    root,
    text="✨ 知りたい年を入力してください ✨",
    font=("Helvetica", 16, "bold"),
    bg="#fffbf0",
    fg="#d35d6e"
)
title_label.pack(pady=20)

# フレームで中央整列
frame = ttk.Frame(root)
frame.pack(pady=10)

# 入力ボックス
year_entry = ttk.Entry(frame, font=("Helvetica", 14), width=15)
year_entry.grid(row=0, column=0, padx=5)

# 実行ボタン
calc_button = ttk.Button(
    frame,
    text="調べる",
    command=calculate_info,
    style="Custom.TButton"
)
calc_button.grid(row=0, column=1)

# 結果表示ラベル
result_label = tk.Label(
    root,
    text="",
    font=("Helvetica", 14),
    bg="#fffbf0",
    fg="#5d6e7d",
    wraplength=350,
    justify="center"
)
result_label.pack(pady=20)

# スタイルの設定
style = ttk.Style()
style.configure(
    "Custom.TButton",
    font=("Helvetica", 14),
    padding=5,
    foreground="#ffffff",
    background="#d35d6e",
    borderwidth=0,
)
style.map(
    "Custom.TButton",
    background=[("active", "#c14a5c")]
)

# アプリ起動
root.mainloop()


💙最後に豆知識

令和の場合、「2025」→ 2+5=7 令和7年とのことです
ぜひ活用して見てください

見ていただき、ありがとうございます😍

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?