Pythonでカレンダーアプリを自作!予定管理がめちゃくちゃ便利に!?【初心者向け】

初心者

Pythonで自作のカレンダーアプリを作ってみました。日付、予定の登録、色分けなど自由自在。シンプルなのに超便利!プログラミング初心者にもぴったりなGUIアプリ開発です。
#Python #カレンダーアプリ #GUI開発 #プログラミング初心者 #自作アプリ #スケジュール管理
import calendar
from rich.console import Console
from rich.table import Table
from rich.text import Text

# 年と月を指定
year = 2025
month = 5

# 曜日ヘッダー
days = [“Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”, “Sun”]

# カレンダー取得
month_cal = calendar.monthcalendar(year, month)

# richコンソール
console = Console()

# タイトル付きテーブル
table = Table(
title=f”[bold green]calendar.month_name[month] year[/bold green]”,
box=None,
show_header=True,
header_style=”bold white on dark_green”,
show_lines=False,
padding=(0, 1)
)

# 各曜日のスタイル
for i, day in enumerate(days):
style = “white”
if day == “Sat”:
style = “bold blue”
elif day == “Sun”:
style = “bold red”
table.add_column(day, justify=”center”, style=style)

# 各週を行として追加
for week in month_cal:
row = []
for i, day in enumerate(week):
if day == 0:
row.append(“”) # 空白の日
else:
# 土曜は青、日曜は赤、それ以外は白
if i == 6:
row.append(f”[bold red]day[/bold red]”)
elif i == 5:
row.append(f”[bold blue]day[/bold blue]”)
else:
row.append(str(day))
table.add_row(*row)

# 出力
console.print(table)

コメント

タイトルとURLをコピーしました