Python - Escribir direccion del fichero en un Entry con tkinter

 
Vista:
sin imagen de perfil
Val: 8
Ha disminuido su posición en 11 puestos en Python (en relación al último mes)
Gráfica de Python

Escribir direccion del fichero en un Entry con tkinter

Publicado por Paco (3 intervenciones) el 18/02/2021 14:19:22
Hola.
Hace pocos días que he comenzado con Python, y lo he hecho para hacerme un ejecutable para uso propio.
De momento ya he hecho la ventana y los botones Examinar, Borrar y Generar.

He conseguido que al clickar sobre Examinar se abra una ventana de dialogo y poder elegir un fichero. En este caso un Excel.

También consigo imprimir en pantalla la dirección entera del fichero, pero me gustaría que esa dirección apareciese en un Entry que he puesto en la ventana, y mas adelante utilizar esa dirección para que en otra fase del código, me graficase esos Excel que iria cargando.

Lamento el como estoy haciendo el programa, pero de programación no se nada, así que todo está muy plano y desorganizado

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from tkinter import filedialog
from tkinter import *
from tkinter import Button
from tkinter import Frame
from tkinter import Label
from tkinter import END
 
 
root = Tk()
 
#Ventana y titulo
root.title("GENERADOR DE GRAFICOS")
root.geometry("600x150")
root.iconbitmap("grafico.ico")
 
frame1 = Frame(root, width=600, height=150)
frame1.pack()
 
 
def abrir_archivo():
    archivo_abierto =  filedialog.askopenfilename(initialdir = "/",title = "Select file", filetypes =((".xls", ".xlsx"), ("all files", "*.*")))
    print (archivo_abierto)
 
def borrar_entrada():
    cuadrotexto.delete(0, END)
 
CrearEspacio1=Label(frame1, text="") #Espacio superior
CrearEspacio1.grid(row =1, column = 2)
 
TextoAbrir=Label(frame1, text="Nombre") #Comentario junto al cuadro de texto
TextoAbrir.grid(row =2, column = 2)
 
CrearEspacio2=Label(frame1, text="") #Espacio intermedio
CrearEspacio2.grid(row =3, column = 2)
 
archivo_abierto = StringVar()
cuadrotexto=Entry(frame1, textvariable=archivo_abierto) #Cuadro de texto donde debe aparecer la ruta absoluta del fichero
cuadrotexto.grid(row = 2, column = 4)
 
Boton_Examinar=Button(frame1, text="Examinar", command=abrir_archivo) #Pulsador Examinar para buscar fichero
Boton_Examinar.grid(row = 4, column = 6)
 
 
Boton_Borrar=Button(frame1, text=" Borrar ", command=borrar_entrada) #Pulsador borrar contenido del cuadro de texto
Boton_Borrar.grid(row = 4, column = 4)
 
Boton_Generar=Button(frame1, text="Generar") #Pulsador aceptar fichero del cuadro de texto
Boton_Generar.grid(row = 4, column = 2)
 
TextoAbrir=Label(frame1, text="") #Espacio inferior
TextoAbrir.grid(row =5, column = 2)
 
root.mainloop()

Espero que me podáis ayudar.
Muchas gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 8
Ha disminuido su posición en 11 puestos en Python (en relación al último mes)
Gráfica de Python

Escribir direccion del fichero en un Entry con tkinter

Publicado por Paco (3 intervenciones) el 18/02/2021 17:52:17
Hola de nuevo.
He limpiado un poco el código, y ya no hay tanta proqueria.

Disculpadme, pero es la primera vez que hago algo asi...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from tkinter import filedialog
from tkinter import *
from tkinter import Button
from tkinter import Frame
from tkinter import Label
from tkinter import END
 
 
root = Tk()
 
#Ventana y titulo
root.title("GENERADOR DE GRAFICOS")
root.geometry("750x200")
root.iconbitmap("grafico.ico")
 
frame1 = Frame(root, width=750, height=200)
frame1.pack()
 
 
def abrir_archivo():
    archivo_abierto =  filedialog.askopenfilename(initialdir = "/",title = "Select file", filetypes =((".xls", ".xlsx"), ("all files", "*.*")))
    print (archivo_abierto)
 
def borrar_entrada():
    cuadrotexto.delete(0, END)
 
TextoAbrir=Label(frame1, text="Nombre") #Comentario junto al cuadro de texto
TextoAbrir.place(x=50, y=40, width=110, height=30)
 
archivo_abierto = StringVar()
cuadrotexto=Entry(frame1, textvariable=archivo_abierto) #Cuadro de texto donde debe aparecer la ruta absoluta del fichero
cuadrotexto.place(x=150, y=40,  width=555, height=30)
 
Boton_Generar=Button(frame1, text="Generar") #Pulsador aceptar fichero del cuadro de texto
Boton_Generar.place(x=50, y=100, width=110, height=30)
 
Boton_Borrar=Button(frame1, text="Borrar", command=borrar_entrada) #Pulsador borrar contenido del cuadro de texto
Boton_Borrar.place(x=325, y=100, width=110, height=30)
 
Boton_Examinar=Button(frame1, text="Examinar", command=abrir_archivo) #Pulsador Examinar para buscar fichero
Boton_Examinar.place(x=600, y=100, width=110, height=30)
 
 
root.mainloop()
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 8
Ha disminuido su posición en 11 puestos en Python (en relación al último mes)
Gráfica de Python

Escribir direccion del fichero en un Entry con tkinter

Publicado por Paco (3 intervenciones) el 18/02/2021 21:17:13
Hola.
De momento lo he solucionado de la siguiente manera:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from tkinter import filedialog
from tkinter import *
from tkinter import Button
from tkinter import Frame
from tkinter import Label
from tkinter import END
from tkinter.filedialog import askopenfilename
 
root = Tk()
 
#Ventana y titulo
root.title("GENERADOR DE GRAFICOS")
root.geometry("750x200")
root.iconbitmap("")
 
frame1 = Frame(root, width=750, height=200)
frame1.pack()
 
global archivo_abierto
 
def Examinar():
    archivo_abierto.set(askopenfilename(title='select new file'))
 
def borrar_entrada():
    cuadrotexto.delete(0, END)
 
 
TextoAbrir=Label(frame1, text="Nombre") #Comentario junto al cuadro de texto
TextoAbrir.place(x=50, y=40, width=110, height=30)
 
archivo_abierto = StringVar()
cuadrotexto=Entry(root, textvariable=archivo_abierto) #Cuadro de texto donde debe aparecer la ruta absoluta del fichero
cuadrotexto.place(x=150, y=40,  width=555, height=30)
 
Boton_Generar=Button(frame1, text="Generar") #Pulsador aceptar fichero del cuadro de texto
Boton_Generar.place(x=50, y=100, width=110, height=30)
 
Boton_Borrar=Button(frame1, text="Borrar", command=borrar_entrada) #Pulsador borrar contenido del cuadro de texto
Boton_Borrar.place(x=325, y=100, width=110, height=30)
 
Boton_Examinar=Button(root, text="Examinar", command=Examinar) #Pulsador Examinar para buscar fichero
Boton_Examinar.place(x=600, y=100, width=110, height=30)
 
root.mainloop()

Por ahora hace lo que creo que necesito.

Muchas gracias.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar