我正在尝试在笔记本中使用tkinter。它有两个按钮,一个只显示一个文本,另一个应该打开一个地图(ipyleaflet)。单击“Say hello”按钮时,将显示输出。但是在“地图”的情况下也不会发生同样的情况。这是一个限制吗?
import tkinter as tk
from ipyleaflet import (
Map,
Marker,
TileLayer, ImageOverlay,
Polyline, Polygon, Rectangle, Circle, CircleMarker,
GeoJSON,
DrawControl
)
def map_print():
m = Map(zoom=0)
dc = DrawControl()
def handle_draw(self, action, geo_json):
print(action)
print(geo_json)
dc.on_draw(handle_draw)
m.add_control(dc)
return(m)
class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.pack()
self.create_widgets()
def create_widgets(self):
self.hello= tk.Button(self)
self.hello["text"] = "Say Hello"
self.hello["command"] = self.say_hello
self.hello.pack(side="top")
self.hey= tk.Button(self)
self.hey["text"] = "Map"
self.hey["command"] = self.say_map
self.hey.pack(side="top")
self.quit = tk.Button(self, text="QUIT", fg="red",
command=root.destroy)
self.quit.pack(side="bottom")
def say_map(self):
M=map_print()
M
def say_hello(self):
print("Hello :)")
root = tk.Tk()
app = Application(master=root)
app.mainloop()