Oct-25-2018, 09:00 PM
My goal is to have an interactive bar chart. I want to open a window containing a text. This shall happen when the user clicks on one of the bars. I started playing around a bit. In the following example, if you click on the left bar a window containing a text pops up. The problem I have, I only want to have the window opening once. So if you click a second time on the left bar, I don't want to open a second window. Therefore my question, how can I check if the window already exists and avoid multiple windows of the same kind.
Thank you very much for your help.
Thank you very much for your help.
def on_press(event):
cont,att = rect[0].contains(event)
if cont == True:
win = tk.Tk()
label1 = ttk.Label(win, text ="Test1").grid(column=0,row=0)
label2 = ttk.Label(win, text ="Test2").grid(column=0,row=1)
label3 = ttk.Label(win, text ="Test3").grid(column=0,row=2)
fig = plt.figure()
ax = fig.add_subplot(111)
x = [1,2,3]
y = [10,20,5]
rect = ax.bar(x,y)
test = rect[0].figure.canvas.mpl_connect('button_press_event', on_press)
plt.show()
