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
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)
        toolbar = NavigationToolbar2Tk(canvas, self)

        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("y co ordinates outside the boundary")
        print("the remaining sentences")
        # axes1.scatter(therestx,theresty, cmap='Paired')
        axes1.scatter(therestx,theresty, cmap='Paired')
    def window_click(event):

    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))
    slider = Scale(window,from_=0, to=maximumdistance, orient=HORIZONTAL,command=getboundary)
    slider.pack(fill = BOTH)
    # print(var.get())
The following error is created -

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

Possibly Related Threads…
Thread Author Replies Views Last Post
  "tkinter.TclError: NULL main window" Rama02 1 430 Feb-04-2021, 06:45 PM
Last Post: deanhystad
  Using Tkinter inside function not working Ensaimadeta 3 480 Dec-23-2020, 02:57 PM
Last Post: deanhystad
  function in new window (tkinter) Dale22 7 649 Nov-24-2020, 11:28 PM
Last Post: Dale22
  [Tkinter] Mouse click without use bind ATARI_LIVE 8 1,831 Oct-23-2020, 10:41 PM
  tkinter | Button color text on Click Maryan 2 605 Oct-09-2020, 08:56 PM
Last Post: Maryan
  Scrollable big image in a window (TKinter) Prospekteur 3 624 Sep-14-2020, 03:06 AM
Last Post: Larz60+
  Run more than one window together with tkinter SmukasPlays 1 474 Aug-24-2020, 05:00 PM
Last Post: Larz60+
  Adding an image to a tkinter window djwilson0495 2 2,197 Aug-23-2020, 11:07 AM
Last Post: ebolisa
  [Tkinter] calling a new window from a tkinter window neuroprogrammer 2 623 Jul-28-2020, 10:59 PM
Last Post: deanhystad
  How to display results from terminal window onto tkinter. buttercup 0 590 Jul-21-2020, 04:41 AM
Last Post: buttercup

Forum Jump:

User Panel Messages

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