user11040244
user11040244

Reputation:

Python Calendar - without Monday

I have a python calendar module which I'm inserting into Tkinter and displaying it. There Is one problem; in May, 2019 : there is no 27th Monday... It goes like

  Su 26 / Mo (nothing) / Tu 27

Where could be a problem, please?

This is the code


#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()

Upvotes: 0

Views: 116

Answers (1)

vb_rises
vb_rises

Reputation: 1907

By default the text is 'center' justify. So the last row is center justified. Change it to 'left' justify.

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()

Output:

Oputput

Upvotes: 1

Related Questions