I create an ip location tracker with a GUI. The app supposed to show details of an specific ip from an API. Everything works right, but when I want to display a map for that specific location, the canvas for map appear but the map is not appear.
To display map I used tkintermapview from tkinter. To display the map I used latitude and longitude from that API to parse them to my map.
Here is the code:
import tkinter as tk
import tkintermapview
import requests
import ipaddress
from tkinter import *
from tkinter.ttk import *
def ipFinder(outputMsg, inputValue):
try:
ipAddress = inputValue.get()
ipaddress.ip_address(ipAddress)
response = requests.get(f'https://ipapi.co/{ipAddress}/json/').json()
ip_version = response.get("version")
city = response.get("city")
region = response.get("region")
country = response.get("country_name")
postalcode = response.get("postal")
continent = response.get("continent_code")
lat = response.get("latitude")
lng = response.get("longitude")
outputMsg.config(text= "Information for " inputValue.get() " are:" "\n"
"IP Version" ' : ' str(ip_version) "\n"
"CITY" ' : ' str(city) "\n"
"REGION" ' : ' str(region) "\n"
"Country" ' : ' str(country) "\n"
"Postal Code" ' : ' str(postalcode) "\n"
"Continent" ' : ' str(continent) "\n"
"Latitude" ' : ' str(lat) "\n"
"Longitude" ' : ' str(lng) "\n")
except:
outputMsg.config(text="Please Enter Correct IP")
# Define LabelFrame to show the map on my app
my_label = tk.LabelFrame(Tk)
my_label.grid(pady=20)
# tkintermapview to fullfield my label with exact location of phone using lat and lng
map_widget = tkintermapview.TkinterMapView(my_label, width=300, height=300, corner_radius=0)
map_widget.set_position(lat, lng)
# set_marker to set the marker on my map to see the location
map_widget.set_marker(lat, lng, text = "Ip Location")
# set_zoom to set the zoom on my map to actually see something
map_widget.set_zoom(10)
map_widget.place(relx=0.5, rely=0.5, anchor=tk.CENTER)
map_widget.grid()
Tk = tk.Tk()
Tk.geometry("600x600 {} {}".format(600, 600))
authorLable = tk.Label(Tk, text="Robert", background='#28334A', foreground="#FFFFFF")
authorLable.grid(row=0, columnspan=4)
inputString = tk.StringVar()
websiteName = tk.Label(Tk, text="Enter ip", background='#28334A', foreground="#F65058")
input_entry = tk.Entry(Tk, textvariable=inputString)
websiteName.grid(row=1)
input_entry.grid(row=1, column=1)
outputMsg = tk.Label(Tk, background='#28334A', foreground="#F65058")
outputMsg.grid(row=3, columnspan=4)
button = tk.Button(Tk, text="Check IP", command=lambda : ipFinder(outputMsg, inputString))
button.grid(row=2, columnspan=4)
Tk.title('IP Checker')
Tk.configure(background='#28334A')
Tk.rowconfigure(0, weight=1)
Tk.columnconfigure(0, weight=1)
Tk.rowconfigure(2, weight=1)
Tk.columnconfigure(2, weight=1)
contents = tk.Frame(Tk)
contents.grid(row=1, column=1)
Tk.mainloop()
Here is an ss with the app:
Any help will be welcome. Thanks in advenced.
CodePudding user response:
I solved it by upgrading the tkintermapview to last version.
@acw1668 Thank you so much for help.