python图形化万年历
时间: 2023-12-19 13:32:17 浏览: 151
以下是一个使用Python实现的图形化万年历的例子:
```python
import calendar
import tkinter as tk
def show_calendar():
year = int(entry_year.get())
month = int(entry_month.get())
cal = calendar.monthcalendar(year, month)
root = tk.Tk()
root.title("Calendar")
frame = tk.Frame(root)
frame.pack()
label_year_month = tk.Label(frame, text=f"{year}年{month}月")
label_year_month.pack()
for week in cal:
week_frame = tk.Frame(frame)
week_frame.pack()
for day in week:
if day == 0:
label_day = tk.Label(week_frame, text=" ")
else:
label_day = tk.Label(week_frame, text=str(day))
label_day.pack(side=tk.LEFT)
root.mainloop()
# 创建GUI界面
root = tk.Tk()
root.title("Calendar")
frame = tk.Frame(root)
frame.pack()
label_year = tk.Label(frame, text="年份:")
label_year.pack(side=tk.LEFT)
entry_year = tk.Entry(frame)
entry_year.pack(side=tk.LEFT)
label_month = tk.Label(frame, text="月份:")
label_month.pack(side=tk.LEFT)
entry_month = tk.Entry(frame)
entry_month.pack(side=tk.LEFT)
button_show = tk.Button(root, text="显示日历", command=show_calendar)
button_show.pack()
root.mainloop()
```
阅读全文