@andrewtsay

Объясните суть функции fill в коде ниже?

from tkinter import *
import calendar
import datetime

def back():
global month, year
month -= 1
if month == 0:
month = 12
year -= 1
fill()

def next():
global month, year
month += 1
if month == 13:
month = 1
year += 1
fill()

def fill():
info_label['text'] = calendar.month_name[month] + ', ' + str(year)
month_days = calendar.monthrange(year, month)[1]
if month == 1:
back_month_days = calendar.monthrange(year - 1, 12)[1]
else:
back_month_days = calendar.monthrange(year, month - 1)[1]
week_day = calendar.monthrange(year, month)[0]

for n in range(month_days):
days[n + week_day]['text'] = n + 1
days[n + week_day]['fg'] = 'black'
if year == now.year and month == now.month and n == now.day:
days[n + week_day - 1]["bg"] = "green"
days[n + week_day]['bg'] = 'grey'
else:
days[n + week_day]['bg'] = 'gray'
for n in range(week_day):
days[week_day - n - 1]['text'] = back_month_days - n + 1
days[week_day - n - 1]['fg'] = 'gray'
days[week_day - n - 1]['bg'] = '#f3f3f3'
for n in range(6 * 7 - month_days - week_day):
days[week_day + month_days + n]['text'] = n + 1
days[week_day + month_days + n]['fg'] = 'gray'
days[week_day + month_days + n]['bg'] = '#f3f3f3'
if month == 1:
days[week_day]['bg'] = 'red'
if month == 1:
days[week_day + 13]['bg'] = 'red'
if month == 3:
days[week_day + 7]['bg'] = 'red'
if month == 3:
days[week_day + 20]['bg'] = 'red'
if month == 5:
days[week_day + 8]['bg'] = 'red'
if month == 6:
days[week_day]['bg'] = 'red'
if month == 9:
days[week_day]['bg'] = 'red'
if month == 10:
days[week_day]['bg'] = 'red'
if month == 12:
days[week_day + 7]['bg'] = 'red'

root = Tk()
root.title('Праздники')
root.geometry('670x350+560+50')
info_label = Label(root,
text='1 Января - Новый год,\n 14 Января - день защитников отечества,\n 8 Марта - Международный женский день,\n 21 Марта - Навруз,\n 9 Мая - День памяти и почести,\n 1 Июня - День детей, \n 1 Сентября - День независимости,\n 1 Октября - День учителя,\n 8 Декабря - День конституции\n',
font="Arial 24 bold", fg="red")
info_label.grid(row=0, column=0)

root = Tk()
root.title("Календарь")
root.geometry('400x400+50+50')
days = []
now = datetime.datetime.now()
year = now.year
month = now.month
day = now.day
back_button = Button(root, text='<', bg="green", fg="#fff", border="3px", pady="5px", command=back)
back_button.grid(row=0, column=0, sticky=NSEW)

next_button = Button(root, text='>', bg="green", fg="#fff", border="3px", pady="5px", command=next)
next_button.grid(row=0, column=6, sticky=NSEW)
info_label = Label(root, text='0', width=1, height=1, font="Arial 24 bold", fg="blue")
info_label.grid(row=0, column=1, columnspan=5, sticky=NSEW)
for n in range(7):
lbl = Label(root, text=calendar.day_abbr[n], width=1, height=1, font='Arial 10 bold', fg='red')
lbl.grid(row=1, column=n, sticky=NSEW)

for row in range(6):
for col in range(7):
lbl = Label(root, text='0', width=4, height=2, font='Arial 16 bold')
lbl.grid(row=row + 2, column=col, sticky=NSEW)
days.append(lbl)

fill()
root.mainloop()
  • Вопрос задан
  • 75 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы