Open callejero666 opened 1 year ago
from tkinter import import tkinter as tk from tkinter import ttk import time from datetime import datetime import pytz from tkcalendar import import csv from tkinter.messagebox import askokcancel, showinfo,showwarning, WARNING
root = Tk() root.geometry("1300x900") root.title("New Calendar Junior") root.config(bg="gray13")
imagen = PhotoImage(file = "atardecer8.png") background = Label(image = imagen, text = "Imagen S.O de fondo") background.place(x = 0, y = 0, relwidth = 1, relheight = 1) #mediada imagen
cal = Calendar(root) cal.place(x=500,y=10,width=380, height=300) cal.config(headersbackground='DodgerBlue4', foreground='white smoke', background='DodgerBlue4',headersforeground='white smoke')
class WordClock: def init(self):
self.clock = Label(root,font=("times",50,"bold"))
self.clock.grid(row=2,column=1,pady=40,padx=20)
self.locations = {"Alaska":"US/Alaska","Amsterdam":"Europe/Amsterdam","Berlin":"Europe/Berlin","Budapest":"Europe/Budapest","Buenos Aires":"America/Buenos_Aires","Caracas":"America/Caracas",
"Chicago":"America/Chicago","Dublin":"Europe/Dublin","Lisbon":"Europe/Lisbon",
"London":"Europe/London","Los Angeles":"America/Los_Angeles","New York":"America/New_York","Moscow":"Europe/Moscow","Paris":"Europe/Paris",
"Rome":"Europe/Rome","Seoul":"Asia/Seoul","Sydney":"Australia/Sydney","Tokyo":"Asia/Tokyo"}
self.location_label = Label(root,text="Hora Local",width=10,font="arial 15 bold",fg="DeepSkyBlue2")
self.location_label.place(x=100,y=10)
self.entry = ttk.Combobox(root,width=42)
self.entry["values"]=["Hora Local","Alaska","Amsterdam","Berlin","Budapest","Buenos Aires","Caracas","Chicago","Dublin","Lisbon","London","Los Angeles",
"New York","Moscow","Paris","Rome","Seoul","Sydney","Tokyo"]
self.entry.set("Hora Local")
self.entry.place(x=20,y=120)
self.times()
def times(self):
if self.entry.get()!="Hora Local":
tz = pytz.timezone(self.locations[self.entry.get()])
zone_time = datetime.now(tz)
current_time = zone_time.strftime("%H:%M:%S")
self.location_label.configure(text='{} Time'.format(self.entry.get()))
else:
current_time=time.strftime("%H:%M:%S")
self.location_label.configure(text=self.entry.get())
self.clock.config(text=current_time,bg="black",fg="DeepSkyBlue2",font="Arial 50 bold")
self.clock.after(200,self.times)
frame2 = Frame(bg="#d3dde3") frame2.place(x=220,y=380,width=250, height=330)
lbl1 = Label(frame2,text="Dia ") lbl1.place(x=3,y=5) textDia=Entry(frame2) textDia.place(x=3,y=30,width=200,height=25)
lbl2 = Label(frame2,text="Fecha ") lbl2.place(x=3,y=55) textFecha=Entry(frame2) textFecha.place(x=3,y=75,width=200,height=25)
lbl3 = Label(frame2,text="Evento ") lbl3.place(x=3,y=105) textEvento=Entry(frame2) textEvento.place(x=3,y=130,width=200,height=25)
lbl4 = Label(frame2,text="Hora inicio ") lbl4.place(x=3,y=160) textInicio=Entry(frame2) textInicio.place(x=3,y=185,width=200,height=25)
lbl5 = Label(frame2,text="Hora fin ") lbl5.place(x=3,y=215) textFin=Entry(frame2) textFin.place(x=3,y=240,width=200,height=25)
lbl6 = Label(frame2,text="Importancia") lbl6.place(x=3,y=270) textImport=Entry(frame2) textImport.place(x=3,y=295,width=200,height=25)
columna=("dia","fecha","evento","hora inicio","hora fin","importancia")
grid = ttk.Treeview(columns=columna,show="headings")
grid.column("dia",width =50) grid.column("fecha",width =50, anchor=CENTER) grid.column("evento",width =100, anchor=CENTER) grid.column("hora inicio",width =70, anchor=CENTER) grid.column("hora fin",width =70, anchor=CENTER) grid.column("importancia",width =70, anchor=CENTER)
grid.heading("dia", text="Dia", anchor=CENTER) grid.heading("fecha", text="Fecha:", anchor=CENTER) grid.heading("evento", text="Evento:", anchor=CENTER) grid.heading("hora inicio", text="Hora inicio:", anchor=CENTER) grid.heading("hora fin", text="Hora fin:", anchor=CENTER) grid.heading("importancia", text="Importancia:", anchor=CENTER)
grid.place(x=500,y=380,width=700,height=330)
def vista(): lista1=[] with open("evento.csv","r", newline="") as archivo: lector = csv.reader(archivo, delimiter=",") lista = list(lector) for sacar in lista: lista1.append(sacar) for lista2 in lista1: grid.insert("",tk.END,values=lista2)
def cargardatos():
dia=textDia.get()
fecha=textFecha.get()
eventos=textEvento.get()
inicio=textInicio.get()
fin=textFin.get()
importancia=textImport.get()
vals = [dia, fecha, eventos, inicio, fin, importancia]
with open("evento.csv","a",newline="") as registro:
writer = csv.writer(registro, lineterminator ="\r", delimiter=",")
writer.writerow(vals)
grid.insert("",END, values=(dia,fecha,eventos,inicio,fin,importancia))
def displaySelectedItem(a):
# clear entries
textDia.delete(0,tk.END)
textFecha.delete(0,tk.END)
textEvento.delete(0,tk.END)
textInicio.delete(0,tk.END)
textFin.delete(0,tk.END)
textImport.delete(0,tk.END)
selectedItem = grid.selection()[0]
textDia.insert(0, grid.item(selectedItem)['values'][0])
textFecha.insert(0, grid.item(selectedItem)['values'][1])
textEvento.insert(0, grid.item(selectedItem)['values'][2])
textInicio.insert(0, grid.item(selectedItem)['values'][3])
textFin.insert(0, grid.item(selectedItem)['values'][4])
textImport.insert(0, grid.item(selectedItem)['values'][5])
grid.bind("<
def edit():
dia=textDia.get()
fecha=textFecha.get()
eventos=textEvento.get()
inicio=textInicio.get()
fin=textFin.get()
importancia=textImport.get()
selectedItem = grid.selection()[0]
vals = dia, fecha, eventos, inicio, fin, importancia
grid.item(selectedItem,values=vals)
with open("evento.csv","r+", newline="") as archivo:
writer=csv.writer(archivo, delimiter=",")
writer.writerow(vals)
grid.item(selectedItem,values=vals)
def eliminar_evento():
selection =grid.selection()
if selection:
for items in selection:
if grid.exists(items):
item=grid.item(items)
fila=item['values']
res= askokcancel(title="Eliminar_Fila",message=("Deseas eliminar esta fila", "\n"+ ",".join(fila) ))
if res:
grid.delete(items)
with open ('evento.csv','r')as file:
reader=csv.reader(file)
rows=list(reader)
with open ('evento.csv','w',newline='') as file:
writer=csv.writer(file)
for r in rows:
if r!= fila:
writer.writerow(r)
showinfo(title="Eliminado", message="La fila ha sido eliminada exitosamente.")
else:
showwarning(title="Error",message="El elemento que intenta eliminar no existe")
btnCargar=Button(root,text="Cargar",command=cargardatos, bg="blue", fg="white") btnCargar.place(x=220,y=320, width=150, height=40)
btnBuscar=Button(root,text="Buscar", bg="blue", fg="white") btnBuscar.place(x=500,y=320, width=150, height=40)
btnModificar=Button(root,text="Modificar",command=edit,bg="blue", fg="white") btnModificar.place(x=760,y=320, width=150, height=40)
btnEliminar=Button(root,text="Eliminar",command=eliminar_evento, bg="blue", fg="white") btnEliminar.place(x=980,y=320, width=150, height=40)
vista()
WordClock() root.mainloop()
``