#gui.py
import tkinter  # importa la libreria Tkinter
w_max=400.0     # ancho de ventana
h_max=300.0     # alto de ventana

def boton():
    # boton de ingreso de texto
    print ("boton", t_entrada.get())
    a=t_entrada.get()
    print (a)
    return
    
def dibuja():
    # esta rutina borra el canvas
    # y dibuja la linea 
    canvas.create_line(t_x1.get(),t_y1.get(), t_x2.get(),t_y2.get(), fill="RED", width=3)
    return

def salida():
    windows.destroy()
    
def erase():
    canvas.delete(tkinter.ALL)
    return
    
def visor(x):
    t_dial.delete(0,5)
    t_dial.insert(0,x)
    return
    
def llena():
    
    t_dial2.insert(0,t_x1.get())
    return


#########################
#       cuerpo principal
#########################


#   Invoco el creador de Tk, que me devuelve una ventana a la que nombro "windows"
windows = tkinter.Tk()
#   a ese objeto le modifico la propiedad titulo
windows.title("VENTANA")

windows.geometry('700x350+300+200')
windows.configure(background = 'lightblue')

#   Invoco el creador del objeto canvas dentro del objeto windows y lo llamo canvas
canvas = tkinter.Canvas(windows,width=w_max, height=h_max,bg='white')
#   Hubico el  objeto canvas dentro del objeto ventana
#   ocupando las dos primera filas y columnas
canvas.grid(column=0, row=1,columnspan=2,rowspan=4) 


# lineas previstas para poder cargar texto

#   creo dentro del objeto windows una etiqueta y lapongo en la fila 0 columna 0
l_titulo =tkinter.Label(windows,text="ARCHIVO")
l_titulo.grid(row=0,column=0)

#   creo dentro del objeto windows una caja de texto para entrada y la pongo en la fila 0 columna 1
t_entrada = tkinter.Entry(windows,width=20)
t_entrada.grid(row=0,column=1)


# creo un boton en el objeto windows y lo pongo en la fila 0 y columna 2 
# los botones toman la accion definida en la funcion del command
b_ok = tkinter.Button(windows, text ="Ok", command = boton)
b_ok.grid(row=0, column=2)

l_x1 =tkinter.Label(windows,text="X1")
l_x1.grid(row=1,column=2)

t_x1 = tkinter.Entry(windows,width=5)
t_x1.grid(row=1,column=3)

l_y1 =tkinter.Label(windows,text="Y1")
l_y1.grid(row=1,column=4)

t_y1 = tkinter.Entry(windows,width=5)
t_y1.grid(row=1,column=5)

l_x2 =tkinter.Label(windows,text="X2")
l_x2.grid(row=2,column=2)

t_x2 = tkinter.Entry(windows,width=5)
t_x2.grid(row=2,column=3)

l_y2 =tkinter.Label(windows,text="Y2")
l_y2.grid(row=2,column=4)

t_y2 = tkinter.Entry(windows,width=5)
t_y2.grid(row=2,column=5)

b_plot = tkinter.Button(windows, text ="Erase", command = erase)
b_plot.grid(row=1, column=6)

b_plot = tkinter.Button(windows, text ="Plot", command = dibuja)
b_plot.grid(row=2, column=6)

b_exit = tkinter.Button(windows, text ="Exit", command = salida,fg="white",bg="red")
b_exit.grid(row=4, column=6)


s_dial=tkinter.Scale(windows,orient="horizontal",command=visor,from_=-10.0,to=10.0,resolution=1.0)
s_dial.grid(row=3,column=3)

t_dial =tkinter.Entry(windows,width=5)
t_dial.grid(row=3,column=5)

t_dial2 =tkinter.Entry(windows,width=5)
t_dial2.grid(row=4,column=5)

b_plot2 = tkinter.Button(windows, text ="Llena", command = llena)
b_plot2.grid(row=4, column=6)


# entro en el loop principal, donde el programa espera los eventos
windows.mainloop()

