I'm trying to print out a calendar in tkinter but it doesn't print aligned. If I print it in the python console it prints fine. I read on stack overflow to use justify = Left
but that still hasn't fixed it.
from tkinter import *
import calendar
tk = Tk()
calendar_ = calendar.TextCalendar(calendar.MONDAY).formatyear(2017)
calendar_gui = Label(tk, text = calendar_, bg = "white", justify = LEFT)
calendar_gui.pack()
print(calendar_)
tk.geometry("1280x720")
tk.title("Calendar")
tk.configure(background = "white")
Change the font of the calendar_gui
to Courier New
, like this:
calendar_gui = tk.Label(window, text=calendar_, bg="white", font=("Courier New", 10, "bold))
This may not always work, however if you don't have Courier New
in the font files.
Also, don't use wildcard imports ( from ... import *
) and don't name your window tk
. It can mess things up.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.