0

我们正在尝试在链接到谷歌日历的电子墨水显示器上显示日历。我们可以显示整个月,但我们希望一次只显示一周,当一周结束时,它将把已经过去的一周更改为下一周。

我们尝试使用“if”和“else”创建循环,但我们还不能让它正确运行。

positions = {
    # positions the code block to appear on certain columns and rows
    'a1': (col1, row1), 'a2': (col2, row1), 'a3': (col3, row1), 'a4': (col4, row1),
    'a5': (col5, row1), 'a6': (col6, row1), 'a7': (col7, row1),

    'b1': (col1, row2), 'b2': (col2, row2), 'b3': (col3, row2), 'b4': (col4, row2),
    'b5': (col5, row2), 'b6': (col6, row2), 'b7': (col7, row2),

    'c1': (col1, row3), 'c2': (col2, row3), 'c3': (col3, row3), 'c4': (col4, row3),
    'c5': (col5, row3), 'c6': (col6, row3), 'c7': (col7, row3),

    'd1': (col1, row4), 'd2': (col2, row4), 'd3': (col3, row4), 'd4': (col4, row4),
    'd5': (col5, row4), 'd6': (col6, row4), 'd7': (col7, row4),

    'e1': (col1, row5), 'e2': (col2, row5), 'e3': (col3, row5), 'e4': (col4, row5),
    'e5': (col5, row5), 'e6': (col6, row5), 'e7': (col7, row5),

    'f1': (col1, row6), 'f2': (col2, row6), 'f3': (col3, row6), 'f4': (col4, row6),
    'f5': (col5, row6), 'f6': (col6, row6), 'f7': (col7, row6)
    }

这是来自另一个调用位置的 .py 文件。

"""使用内置的日历功能,为每个月份的数字(1,2,3,...28,29,30)绘制图标""" cal = calendar.monthcalendar(time.year, time.月)

        while True:

            if numbers in cal[0]:
                image.paste(im_open(dpath+str(numbers)+'.jpeg'), positions['a'+str(cal[0].index(numbers)+1)])
            elif numbers in cal[1]:
                image.paste(im_open(dpath+str(numbers)+'.jpeg'), positions['b'+str(cal[1].index(numbers)+1)])
            elif numbers in cal[2]:
                image.paste(im_open(dpath+str(numbers)+'.jpeg'), positions['c'+str(cal[2].index(numbers)+1)])
            elif numbers in cal[3]:
                image.paste(im_open(dpath+str(numbers)+'.jpeg'), positions['d'+str(cal[3].index(numbers)+1)])
            elif numbers in cal[4]:
                image.paste(im_open(dpath+str(numbers)+'.jpeg'), positions['e'+str(cal[4].index(numbers)+1)])
            elif len(cal) is 6:
                break
            else numbers in cal[5]:
                image.paste(im_open(dpath+str(numbers)+'.jpeg'), positions['f'+str(cal[5].index(numbers)+1)])

例如,我们希望它显示星期一 2 到星期日 8,然后在日期从 8 日更改为 9 日时更改为星期一 9 到 16 日。到目前为止,我们的实际结果要么是整个月的节目,要么是一周的节目,但它可能会显示错误的一周和/或在一周结束时不会改变。

4

0 回答 0