The Tkinter Text control failed to get the text selected by the mouse

the purpose is to get the text selected by the mouse through the Tkinter Text control

the reference code is as follows:
from-start-and-end-indices-values-from-wordstart-to-w" rel=" nofollow noreferrer "> https://stackoverflow.com/que.

part of my code:

the whole is encapsulated in a class

self.Scrolledtext1 = ScrolledText(top)
        self.Scrolledtext1.place(relx=0.46, rely=0.19, relheight=0.62
                , relwidth=0.4)
        self.Scrolledtext1.configure(background="white")
        self.Scrolledtext1.configure(font="TkTextFont")
        self.Scrolledtext1.configure(foreground="black")
        self.Scrolledtext1.configure(highlightbackground="-sharpd9d9d9")
        self.Scrolledtext1.configure(highlightcolor="black")
        self.Scrolledtext1.configure(insertbackground="black")

def button_down(self,):
            global s
            s = self.Text1.index("@%s,%s wordstart" % (event.x, event.y))

        def button_up(self, ):
            global e
            e = self.Text1.index("@%s,%s wordend" % (event.x, event.y))

 
        def test(self,):
            print(self.Scrolledtext1.get(s,e))
            
        self.Scrolledtext1.bind("<Button-1>", button_down)
        self.Scrolledtext1.bind("<ButtonRelease-1>", button_up)
        self.Button2.configure(command=test(self,))

but strangely, always making an error:

seek advice from heroes

Mar.02,2021
Menu