我有一个要插入到Tkinter并显示它的python日历模块。
有一个问题。在May, 2019
中:没有第27个星期一……就像
Su 26 / Mo (nothing) / Tu 27
请问哪里有问题?
这是代码
#as simple monthly calendar with Tkinter
# give calendar and Tkinter abbreviated namespaces
import calendar as cd
import tkinter as tk
# supply year and month
year = 2019
month = 5 # jan=1
# assign the month's calendar to a multiline string
str1 = cd.month(year, month)
# create the window form and call it root (typical)
root = tk.Tk()
root.title("Monthly Calendar")
# pick a fixed font like courier so spaces behave right
label1 = tk.Label(root, text=str1, font=('courier', 14, 'bold'), bg='yellow')
label1.pack(padx=3, pady=5)
# run the event loop (needed)
root.mainloop()
答案 0 :(得分:2)
默认情况下,文本为“居中”对齐。因此,最后一行是居中对齐的。将其更改为“左”对齐。
import calendar as cd
import tkinter as tk
import calendar
# supply year and month
year = 2019
month = 1 # jan=1
# assign the month's calendar to a multiline string
str1 = cd.month(year, month)
# create the window form and call it root (typical)
root = tk.Tk()
root.title("Monthly Calendar")
# pick a fixed font like courier so spaces behave right
label1 = tk.Label(root, text=str1, font=('courier', 14,'bold'), bg='yellow',justify='left')
label1.pack()
# run the event loop (needed)
root.mainloop()
输出: