LoginSignup
1
7

More than 1 year has passed since last update.

pythonでカレンダーアプリ作成

Last updated at Posted at 2021-07-30

カレンダーアプリの作成を行いました!

コードは以下の通りになります。

Qiita.py

import tkinter as tk
import calendar as cl

tkinterとcalendarをimportし、asを使って省略

def pre_month():
    global a
    global b

    if b == 1:
        b = 12
        a = a - 1
    else:
         b = b - 1



    lbl.configure(text=cl.month(a,b))

関数を追加し、ひと月前を表示させる
ラベル表示を変更

def add_month():
    global a
    global b

    if b == 12:
        b = 1
        a = a + 1
    else:
        b = b + 1

    lbl.configure(text=cl.month(a,b))

関数を追加し、ひと月先を表示させる
ラベル表示を変更

root = tk.Tk()
root.geometry("300x200")
root.title("カレンダー")

画面表示を準備

a=2021
b=4

変数を作成し、y,mに数字を入れる

cv = tk.Canvas(root,width=400,height=300,bg="white")
cv.pack()

背景色を追加 今回は白に設定

lbl = tk.Label(text=cl.month(a,b))

lbl.pack()

カレンダーモジュールを使って文字列型としてカレンダー形式が返ってくる
ラベルとラベルの配置を作成

btn1 = tk.Button(text="←",command=pre_month)
btn2 = tk.Button(text="→",command=add_month)

btn1.place(x=100,y=150)
btn2.place(x=150,y=150)

ボタンとボタンの配置を作成

tk.mainloop()

カレンダーアプリ3.gif

実行結果 

カレンダーアプリの完成になります。

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