0

Trying to write a little calendar program that displays on my desktop. Everything works, except the rows in the output are center-justified and not the nice calendar grid layout. I'm pretty sure it's something with the label.config function. I am stuck. Python 3.7 on Windows 10.

    import calendar as cd
    import tkinter as tk
    from datetime import date
    from datetime import datetime
    from tkinter import *

    root = Tk()

    root.tk_setPalette('#000000')
    label = tk.Label(text="", fg="Light Blue")
    label.place(x=1,y=1)

    now = date.today()
    year = now.year
    month = now.month
    c = cd.TextCalendar(cd.SUNDAY)
    data = c.formatmonth(year,month)
    label.config(text=data)

    root.lift()
    root.overrideredirect(1)
    root.geometry("+530+1")
    root.geometry("130x130")
    root.mainloop()

2 Answers 2

1

You need to use a monospaced font and also add justify to your label.

label = tk.Label(text="", fg="Light Blue",font="Courier",justify="left")
3
  • It displays the actual month that all the 3 minute YouTube videos show. Font is pre-formatted. Tried every justify parameter, too. The rows with only 1 or 2 dates in them just move left or right. Tried =center, too. Mar 23, 2019 at 1:25
  • I'm not sure what 3 minute YouTube videos you are referring to. If you use the above code, it should show up properly formatted (as least on my Windows 7 Python 3.7)
    – Henry Yik
    Mar 23, 2019 at 14:22
  • I'm a little dense sometimes, more if you ask my wife. Specifying the font got me in the right direction. Mar 24, 2019 at 2:30
0

FINALLY, found a way.

import calendar as cd
import tkinter as tk
from tkinter import ttk
from datetime import date
from datetime import datetime
from tkinter import *

now = date.today()
year = now.year
month = now.month
c = cd.TextCalendar(cd.SUNDAY)
root = Tk()
data = Text(root, fg="Light Blue", font=("Consolas", 10), borderwidth=0)
data.pack()
x = c.formatmonth(year,month)
data.insert(END, x)

root.tk_setPalette('#000000')

label = tk.Label(text="")
label.place(x=1,y=1)

root.lift()
root.overrideredirect(1)
root.geometry("+500+8")
root.geometry("150x125")
root.mainloop()    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.