David Robinson
David Robinson

Reputation: 36

Trying to write a little calendar program that displays on my desktop

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

Upvotes: 0

Views: 82

Answers (2)

David Robinson
David Robinson

Reputation: 36

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

Upvotes: 0

Henry Yik
Henry Yik

Reputation: 22503

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

Upvotes: 1

Related Questions