Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My_first_Calendar
#1
Hola soy muy nueva en Python, estoy intentando crear un calendario con este código.

from tkinter import *
from tkcalendar import *

root = Tk()
root. Title("Calendario")
root. Geometry("500x350")
root.config(bg="gray")
cal = Calendar(root, select="day", year=2024, month=5, day=28)
cal.pack(pady=20, fill='both', expand='yes')

def Fecha():
    Label_text.config(text="Fecha de hoy " + cal.get_date())

Button = Button(root, text="fecha", command=Fecha)
Button.pack(pady=20)

Label_text = Label(root, text="")
Label_text.pack(pady=20)

root.mainloop()
He configurado el Path e instalado tkcalendar, al ejecutar el código me sale este error:
"NameError: name 'Calendar' is not defined" no sé cómo resolverlo.

¿Alguien podría ayudarme?
Gracias!
Gribouillis write May-28-2024, 08:11 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
Los errores que tengo yo:

Quote:AttributeError: '_tkinter.tkapp' object has no attribute 'Title'

tambien:

Quote:AttributeError: '_tkinter.tkapp' object has no attribute 'Geometry'

Hay que escribir:

Quote:root.title("Calendario") # la letra t pequeña

y

Quote:root.geometry("500x350") · la letra g pequeña

así funciona en mi ordenador en Idle:

from tkinter import *
from tkcalendar import *

def myApp():
    #from tkinter import *
    #from tkcalendar import *
     
    root = Tk()
    root.title("Calendario")
    root.geometry("500x350")
    root.config(bg="gray")
    cal = Calendar(root, select="day", year=2024, month=5, day=28)
    cal.pack(pady=20, fill='both', expand='yes')
     
    def Fecha():
        Label_text.config(text="Fecha de hoy " + cal.get_date())
     
    Button = Button(root, text="fecha", command=Fecha)
    Button.pack(pady=20)
     
    Label_text = Label(root, text="")
    Label_text.pack(pady=20)
     
    root.mainloop()
¡Pero, esto con tkinter, no soy experto! ¡Suerte!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020