介绍

​ 这是一个可以为每个月生成日历的项目。该应用程序包含一个显示实际日历的简单功能。

​ 这是在一个窗口应用程序中创建的,它使用 tkinter 模块来可视化应用程序的外观并提供一些用于开发的多媒体平台 。您可以根据您输入的内容显示日历的完整列表,该应用程序将在输入月份和年份后立即显示日历。这是是使用基本的 Python 编码创建的。

特点

  1. 用 tkinter 进行界面的开发
  2. 使用 calendar 进行日历的制作

结果展示

image-20221231193647062

源代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from tkinter import *
import tkinter as tk
from PIL import ImageTk, Image
import calendar
root = tk.Tk()
root.geometry('400x300')
root.title('日历')


# 日历制作函数
def show():

m = int(month.get())
y = int(year.get())

# 使用calendar库生成日历
output = calendar.month(y,m)
print(output)
cal.insert('end',output)


# 清除函数
def clear():
cal.delete(1.0,'end')


# 退出函数
def exit():
root.destroy()


# 左上角的显示,美化
title = Label(root,text="日历",font=('宋体','18','bold'))
title.place(x=40,y=10)

# 年标签,用来提示用户输入
y_label = Label(root,text="年",font=('宋体','12','bold'))
y_label.place(x=70,y=80)

# 获取用户输入年标签的值
# Spinbox用于整数的显示与输入
year = Spinbox(root, from_= 2022, to = 3000,width="8")
year.place(x=140,y=80)


# 月标签,用来提示用户输入
m_label = Label(root,text="月",font=('verdana','12','bold'))
m_label.place(x=210,y=80)
# 获取用户输入月标签的值
month = Spinbox(root, from_= 1, to = 12,width="5")
month.place(x=260,y=80)



# 显示日历的区域
cal = Text(root,width=33,height=8,relief=RIDGE,borderwidth=2)
cal.place(x=70,y=110)

# 显示按钮
show = Button(root,text="显示",font=('宋体',12,'bold'),relief=RIDGE,borderwidth=2,command=show)
show.place(x=140,y=250)

# 清除按钮
clear = Button(root,text="清除",font=('宋体',12,'bold'),relief=RIDGE,borderwidth=2,command=clear)
clear.place(x=200,y=250)

# 退出按钮
exit = Button(root,text="退出",font=('宋体',12,'bold'),relief=RIDGE,borderwidth=2,command=exit)
exit.place(x=260,y=250)


if __name__ == "__main__":
root.mainloop()