ventana tutorial ejemplos cerrar botones python tkinter

tutorial - tkinter python 3



Crea una aplicaciĆ³n simple en tkinter para mostrar el mapa (1)

Soy nuevo en Tkinter,

Tengo un programa que toma CSV como entrada que contiene la geo-ubicación de outlet, lo muestra en un mapa, lo guarda como HTML.

formato de mi csv:

outlet_code Latitude Longitude 100 22.564 42.48 200 23.465 41.65 ... and so on ...

A continuación está mi código python para tomar este CSV y ponerlo en un mapa.

import pandas as pd import folium map_osm = folium.Map(location=[23.5747,58.1832],tiles=''https://korona.geog.uni-heidelberg.de/tiles/roads/x={x}&y={y}&z={z}'',attr= ''Imagery from <a href="http://giscience.uni-hd.de/">GIScience Research Group @ University of Heidelberg</a> &mdash; Map data &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'') df = pd.read_excel("path/to/file.csv") for index, row in df.iterrows(): folium.Marker(location=[row[''Latitude''], row[''Longitude'']], popup=str(row[''outlet_code'']),icon=folium.Icon(color=''red'',icon=''location'', prefix=''ion-ios'')).add_to(map_osm) map_osm

Esto llevará la visualización map_osm

La manera alternativa es guardar map_osm como HTML

map_osm.save(''path/map_1.html'')

Lo que busco es una GUI que haga lo mismo.

es decir, solicite al usuario que ingrese el CSV, luego ejecute mi código a continuación y muestre el resultado o al menos guárdelo en una ubicación.

Cualquier pista será útil


Su pregunta sería mejor recibida si hubiera proporcionado algún código que haya intentado escribir para la parte de la GUI de su pregunta. Sé (y todos los demás que publicaron sus comentarios) que tkinter está bien documentado y tiene innumerables sitios de tutoriales y videos de YouTube.

Sin embargo, si ha tratado de escribir código usando tkinter y simplemente no entiende lo que está sucediendo, he escrito un pequeño ejemplo básico de cómo escribir una GUI que abrirá un archivo e imprimirá cada línea en la consola.

Esto no responderá correctamente a su pregunta, pero lo orientará en la dirección correcta.

Esta es una versión no-OOP que a juzgar por su código existente puede comprender mejor.

# importing tkinter as tk to prevent any overlap with built in methods. import tkinter as tk # filedialog is used in this case to save the file path selected by the user. from tkinter import filedialog root = tk.Tk() file_path = "" def open_and_prep(): # global is needed to interact with variables in the global name space global file_path # askopefilename is used to retrieve the file path and file name. file_path = filedialog.askopenfilename() def process_open_file(): global file_path # do what you want with the file here. if file_path != "": # opens file from file path and prints each line. with open(file_path,"r") as testr: for line in testr: print (line) # create Button that link to methods used to get file path. tk.Button(root, text="Open file", command=open_and_prep).pack() # create Button that link to methods used to process said file. tk.Button(root, text="Print Content", command=process_open_file).pack() root.mainloop()

Con este ejemplo, debería ser capaz de descubrir cómo abrir su archivo y procesarlo dentro de una GUI de tkinter.

Para una opción más OOP:

import tkinter as tk from tkinter import filedialog # this class is an instance of a Frame. It is not required to do it this way. # this is just my preferred method. class ReadFile(tk.Frame): def __init__(self): tk.Frame.__init__(self) # we need to make sure that this instance of tk.Frame is visible. self.pack() # create Button that link to methods used to get file path. tk.Button(self, text="Open file", command=self.open_and_prep).pack() # create Button that link to methods used to process said file. tk.Button(self, text="Print Content", command=self.process_open_file).pack() def open_and_prep(self): # askopefilename is used to retrieve the file path and file name. self.file_path = filedialog.askopenfilename() def process_open_file(self): # do what you want with the file here. if self.file_path != "": # opens file from file path and prints each line. with open(self.file_path,"r") as testr: for line in testr: print (line) if __name__ == "__main__": # tkinter requires one use of Tk() to start GUI root = tk.Tk() TestApp = ReadFile() # tkinter requires one use of mainloop() to manage the loop and updates of the GUI root.mainloop()