При наведении и щелчке ярлыка сделайте что-нибудь - PullRequest
0 голосов
/ 18 апреля 2020

У меня есть ярлык, и я хочу выполнить некоторые действия при наведении курсора и щелкнуть, но приведенный ниже код не работает.

class LoginForm:
    def __init__(self,root):    
        Label(text='Don\'t have an account? Create one!', font='Arial 10').place(relx=0.5, rely=0.8, anchor=CENTER)
        Label.bind( "<Button>",self.mouseClick)
    def mouseClick(self,event):
        print('x')

И я получил следующую ошибку AttributeError: 'str' object has no attribute '_bind' Кто-нибудь знает, как исправить эта проблема?

1 Ответ

1 голос
/ 18 апреля 2020

Ваш код может быть:

class LoginForm:
    def __init__(self,root):    
        exmpleText_widget = Label(text='Don\'t have an account? Create one!', font='Arial 10') # assgin it to a variable 
        exmpleText_widget.place(relx=0.5, rely=0.8, anchor=CENTER)
        # exmpleText_widget.bind( "<Button>",self.mouseClick) # This is mouse button event,All the mouse button pressed on this widget will call the function.
        exmpleText_widget.bind("<Enter>",self.mouseClick) # This can be an easy mouse hover event
        exmpleText_widget.bind("<Button-1>",function) # mouse left button pressed on this widget will call the function.
        # exmpleText_widget.bind("<Leave>",function) # this will call the function when mouse leave this widget.
    def mouseClick(self,event):
        print('x')
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...