【问题标题】:How can i change the position of the days(number) in tkcalendar如何更改 tkcalendar 中天数(数字)的位置
【发布时间】:2021-03-31 19:13:07
【问题描述】:

我希望将每个正方形中的天数从中间移到左上角。我已经阅读了 tkcalendar 的文档,但我无法在网上找到任何东西。我无法尝试任何事情,因为我还没有看到任何这样做的例子。如果可能的话,有人可以帮我解决这个问题吗?

python版本= 2.7.16

系统 = macOS Mojave 10.14.6

编码水平 = 菜鸟 - 初学者

感谢您的帮助和时间。

【问题讨论】:

  • Python 2.7 自 2020 年起已失去支持。为什么不更新到 3.9。
  • 我有一个文件夹,上面写着 Python 3.9(我最近在删除了我能找到的所有旧 Python 安装后下载了它)但终端告诉我我的 Python 版本是 2.7。我可能做错了什么,但我想这是另一个问题。 @酷云

标签: python tkcalendar


【解决方案1】:

没有选项可以更改日期编号的位置。因此,有必要深入到小部件的源代码中进行操作。这些日子只是标签,因此可以通过将其anchor 选项设置为"nw" 来获得所需的位置。它们存储在名为._calendar 的列表列表中(每周一个列表):

import tkinter as tk
from tkcalendar import Calendar

class MyCalendar(Calendar):
    def __init__(self, master, **kw):
        Calendar.__init__(self, master, **kw)

        for row in self._calendar:
            for label in row:
                label['anchor'] = "nw"

        # # uncomment this block to align left weekday names
        # for label in self._week_days:
        #     label['anchor'] = "w"


root = tk.Tk()
cal = MyCalendar(root, showweeknumbers=False)
cal.pack(fill='both', expand=True)
root.geometry("400x300")
root.mainloop()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-17
    • 2022-01-08
    • 2018-08-29
    • 1970-01-01
    相关资源
    最近更新 更多