Aug-01-2023, 06:48 PM
(This post was last modified: Aug-01-2023, 06:48 PM by deanhystad.)
Why are you setting the mouse position and calling mouse click? Is that supposed to press the zoom button? zoom and set_zoom() are part of the map api, why not use them? You've posted code that uses the set_zoom() function.
Below is something I posted before with the addition of binding the arrow keys to zoom in and out.
Below is something I posted before with the addition of binding the arrow keys to zoom in and out.
import tkinter as tk from tkintermapview import TkinterMapView class MyWindow(tk.Tk): """A window that selects one of several pages to display.""" def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.map = TkinterMapView(self, width=800, height=600, corner_radius=0) self.map.pack(expand=True, fill=tk.BOTH) self.map.set_position(60.03345, 11.35806) # Norway self.map.set_address("fjellvegen 4, auli, norway", marker=True) self.map.set_zoom(16) self.zoom_label = tk.Label(self, text="Zoom = 16", font=(None, 24), width=20) self.zoom_label.pack(padx=10, pady=10) for key in ("<Left>", "<Right>", "<Up>", "<Down>"): self.bind(key, self.zoom) def zoom(self, event): increment = {"Up": 1, "Right": 1, "Down": -1, "Left": -1}.get(event.keysym, 0) value = max(1, min(19, self.map.zoom + increment)) self.zoom_label["text"] = f"Zoom = {value}" self.map.set_zoom(value) MyWindow().mainloop()
Quote:I wanted to keep track of zoom level on his appThe best way to "keep track" of the zoom level is ask the map what the current zoom level is. There are too many ways this can change. You can change the zoom programmatically. You can change the zoom by hitting the zoom in (+) and out (-) buttons. You can zoom using the mouse wheel. There might be a way to have the map tell you when the zoom level changes. I didn't see it, but that doesn't mean it isn't there. If you want to display the current zoom level you could fire off an event that runs periodically to update the zoom display (use tkinter.after()). If you just want to know what the current zoom is, to save in a configuration file for example, just ask the map.zoom.