GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — TkinterMapView/examples/map_view_demo.py at main · https-github-com-nzysoft/TkinterMapView

Expand file tree

/

map_view_demo.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
126 lines (91 loc) · 4.53 KB
/

map_view_demo.py

Copy path

File metadata and controls

126 lines (91 loc) · 4.53 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import sys
import tkinter
import tkinter.messagebox
from tkintermapview import TkinterMapView
class App(tkinter.Tk):
APP_NAME = "map_view_demo.py"
WIDTH = 800
HEIGHT = 750
def __init__(self, *args, **kwargs):
tkinter.Tk.__init__(self, *args, **kwargs)
self.title(self.APP_NAME)
self.geometry(f"{self.WIDTH}x{self.HEIGHT}")
self.protocol("WM_DELETE_WINDOW", self.on_closing)
self.bind("<Return>", self.search)
if sys.platform == "darwin":
self.bind("<Command-q>", self.on_closing)
self.bind("<Command-w>", self.on_closing)
self.grid_columnconfigure(0, weight=1)
self.grid_columnconfigure(1, weight=0)
self.grid_columnconfigure(2, weight=0)
self.grid_rowconfigure(1, weight=1)
self.search_bar = tkinter.Entry(self, width=50)
self.search_bar.grid(row=0, column=0, pady=10, padx=10, sticky="we")
self.search_bar.focus()
self.search_bar_button = tkinter.Button(master=self, width=8, text="Search", command=self.search)
self.search_bar_button.grid(row=0, column=1, pady=10, padx=10)
self.search_bar_clear = tkinter.Button(master=self, width=8, text="Clear", command=self.clear)
self.search_bar_clear.grid(row=0, column=2, pady=10, padx=10)
self.map_widget = TkinterMapView(width=self.WIDTH, height=600, corner_radius=0)
self.map_widget.grid(row=1, column=0, columnspan=3, sticky="nsew")
self.marker_list_box = tkinter.Listbox(self, height=8)
self.marker_list_box.grid(row=2, column=0, columnspan=1, sticky="ew", padx=10, pady=10)
self.listbox_button_frame = tkinter.Frame(master=self)
self.listbox_button_frame.grid(row=2, column=1, sticky="nsew", columnspan=2)
self.listbox_button_frame.grid_columnconfigure(0, weight=1)
self.save_marker_button = tkinter.Button(master=self.listbox_button_frame, width=20, text="save current marker",
command=self.save_marker)
self.save_marker_button.grid(row=0, column=0, pady=10, padx=10)
self.clear_marker_button = tkinter.Button(master=self.listbox_button_frame, width=20, text="clear marker list",
command=self.clear_marker_list)
self.clear_marker_button.grid(row=1, column=0, pady=10, padx=10)
self.connect_marker_button = tkinter.Button(master=self.listbox_button_frame, width=20, text="connect marker with path",
command=self.connect_marker)
self.connect_marker_button.grid(row=2, column=0, pady=10, padx=10)
self.map_widget.set_address("NYC")
self.marker_list = []
self.marker_path = None
self.search_marker = None
self.search_in_progress = False
def search(self, event=None):
if not self.search_in_progress:
self.search_in_progress = True
if self.search_marker not in self.marker_list:
self.map_widget.delete(self.search_marker)
address = self.search_bar.get()
self.search_marker = self.map_widget.set_address(address, marker=True)
if self.search_marker is False:
# address was invalid (return value is False)
self.search_marker = None
self.search_in_progress = False
def save_marker(self):
if self.search_marker is not None:
self.marker_list_box.insert(tkinter.END, f" {len(self.marker_list)}. {self.search_marker.text} ")
self.marker_list_box.see(tkinter.END)
self.marker_list.append(self.search_marker)
def clear_marker_list(self):
for marker in self.marker_list:
self.map_widget.delete(marker)
self.marker_list_box.delete(0, tkinter.END)
self.marker_list.clear()
self.connect_marker()
def connect_marker(self):
print(self.marker_list)
position_list = []
for marker in self.marker_list:
position_list.append(marker.position)
if self.marker_path is not None:
self.map_widget.delete(self.marker_path)
if len(position_list) > 0:
self.marker_path = self.map_widget.set_path(position_list)
def clear(self):
self.search_bar.delete(0, last=tkinter.END)
self.map_widget.delete(self.search_marker)
def on_closing(self, event=0):
self.destroy()
exit()
def start(self):
self.mainloop()
if __name__ == "__main__":
app = App()
app.start()
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.