Python Forum
[Tkinter] Mouse click event not working on multiple tkinter window
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Mouse click event not working on multiple tkinter window
#1
In the below code mpl_connect works for the main window. But when a window using Toplevel() is called. mpl_connect doesn't work. Both codes are same. So whats the issue here?

This code is in the main window of tkinter
        canvas = FigureCanvasTkAgg(f, self)
        f.canvas.mpl_connect('button_press_event', on_click)
        f.canvas.mpl_connect('button_release_event', off_click)
        canvas.draw()
        toolbar = NavigationToolbar2Tk(canvas, self)
        toolbar.update()
        toolbar.pack()

        canvas.get_tk_widget().pack(side = BOTTOM, fill = BOTH, expand = True)

        text_input = Entry(self)
        text_input.pack(side = LEFT)
        input_button=Button(self, height=1, width=10, text="Find", command=lambda: new_window(x,y,text_input))
        input_button.pack(side = LEFT)
When text_input button is called the below function is called

"Menu bar functionality starts here"
def new_window(tuplex,tupley,text_input):

    def getboundary(event):
        # print(slider.get())
        boundary = slider.get()
        therestx, theresty, thecoordinates = plottingthe_words_outside_a_boundary(dictionary, distance_list, boundary)
        sentences = returning_sentences_of_the_remaining_words(thecoordinates, sent_dic)

        print("x co ordinates outside the boundary")
        print(therestx)
        print("y co ordinates outside the boundary")
        print(theresty)
        print("the remaining sentences")
        print(sentences)
        # axes1.scatter(therestx,theresty, cmap='Paired')
        axes1.clear()
        axes1.scatter(therestx,theresty, cmap='Paired')
        word_canvas.draw()
    def window_click(event):
        print("Something")


    mapx,mapy = plottingdesiredword(labels, tuplex, tupley, text_input.get())
    dictionary, distance_list = dictionaryofeuclideandistanceandtheircoordinates(labels, tuplex, tupley, text_input.get())
    maximumdistance = max(distance_list)

    window = Tk.Toplevel()
    window.minsize(width=1080, height=900)
    fig, axes1 = plt.subplots()


    axes1.scatter(mapx, mapy, cmap='Paired')

    word_canvas = FigureCanvasTkAgg(fig, window)
    # word_canvas.bind("<Button-1>", window_click)
    fig.word_canvas.mpl_connect('button_press_event', window_click)
    plot_widget = word_canvas.get_tk_widget()
    plot_widget.pack(side = TOP, fill = BOTH, expand = True)


    help = Label(window, text="Slide to set boundary",font=("Helvetica", 16))
    help.pack()
    slider = Scale(window,from_=0, to=maximumdistance, orient=HORIZONTAL,command=getboundary)
    slider.pack(fill = BOTH)
    # print(var.get())
    word_canvas.draw()
The following error is created -

File "root.py", line 481, in new_window
fig.word_canvas.mpl_connect('button_press_event', window_click)
AttributeError: 'Figure' object has no attribute 'word_canvas'
Reply
#2
please show all each script in its own single code window so that it can be run
Thank you
Reply
#3
And explain what "doesn't work" means.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 341 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  tkinter - touchscreen, push the button like click the mouse John64 5 742 Jan-06-2024, 03:45 PM
Last Post: deanhystad
  Using Tkinter inside function not working Ensaimadeta 5 4,858 Dec-03-2023, 01:50 PM
Last Post: deanhystad
  Tkinter multiple windows in the same window tomro91 1 785 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  Centering and adding a push button to a grid window, TKinter Edward_ 15 4,374 May-25-2023, 07:37 PM
Last Post: deanhystad
Exclamation Update Point Coordinates from Mouse Event in a Plot Jguillerm 2 1,244 Jan-10-2023, 07:53 AM
Last Post: Jguillerm
  [Tkinter] Open tkinter colorchooser at toplevel (so I can select/focus on either window) tabreturn 4 1,830 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  [Tkinter] Background inactivity timer when tkinter window is not active DBox 4 2,862 Apr-16-2022, 04:04 PM
Last Post: DBox
  why my list changes to a string as I move to another window in tkinter? pymn 4 2,546 Feb-17-2022, 07:02 AM
Last Post: pymn
  tkinter toggle buttons not working Nu2Python 26 6,767 Jan-23-2022, 06:49 PM
Last Post: Nu2Python

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020