Когда я нажимаю на точку на холсте (на графике [0] == 2, режим), а не на одно, открывается несколько (около 10) окон tkinter с запросом долготы и широты
def on_press(self, event):
initial_x=round(event.xdata,2)
initial_y=round(event.ydata,2)
if(plot[0]=='2'):
master = tk.Tk()
tk.Label(master, text="Source ").grid(row=0)
tk.Label(master, text="Destination ").grid(row=1)
e = tk.Entry(master)
f = tk.Entry(master)
e.grid(row=0, column=1)
f.grid(row=1, column=1)
def show_entry_fields():
src = e.get()
dest = f.get()
global flag
flag = 0
for i in range(0, nRoute):
if((c1[i]==src and c2[i]==dest) or (c1[i]==dest and c2[i]==src)):
c9[i]='0';
flag = 1
if(flag==0):
# print("no two such locations found")
initialPaths = extraPaths
for i in range(0, initialPaths):
if((kneeSrc[i]==src and kneeDest[i]==dest) or (kneeSrc[i]==dest and kneeDest[i]==src)):
pass
master.destroy()
tk.Button(master, text='Quit', command=master.destroy).grid(row=3, column=0, sticky=tk.W)
tk.Button(master, text='Okay', command=show_entry_fields).grid(row=3, column=1, sticky=tk.W, pady=4)
self.after(100,master.mainloop())
window.destroy()
if(plot[0]=='1'):
for i in range(0,nBus):
if((round(busDict[col2[i]][2],2)==initial_x) and (round(busDict[col2[i]][3],2)==initial_y)):
busDict[col2[i]][2]=0.0
busDict[col2[i]][3]=0.0
if event.inaxes != self.point.axes: return
if DraggablePoint.lock is not None: return
contains, attrd = self.point.contains(event)
if not contains: return
self.press = (self.point.center), event.xdata, event.ydata
DraggablePoint.lock = self
# draw everything but the selected rectangle and store the pixel buffer
canvas = self.point.figure.canvas
axes = self.point.axes
self.point.set_animated(True)
canvas.draw()
Какмогу ли я изменить код так, чтобы в один клик генерировалось только одно окно tkinter