将鼠标悬停在 tkinter 中的任何一个上时,如何突出显示两个不同的标签?

问题描述

我正在使用 tkinter 构建一个小型应用程序,它向您显示在特定给定时间间隔内完成的工作列表,格式如下

      co11              col2

   Time done         Activity name

下面是代码。因为当我将鼠标悬停在 for 循环内的两个标签之一上时,两列相距很远,所以我希望两个标签都突出显示以便于识别时间完成活动名称。我已将网格布局中的标签实现为单独的标签。

                def on_click(e):
                    e.widget['bg']='#fafafa'
                def on_leave(e):
                    e.widget['bg']='#dcdcdc'
                if result1:
                    Label(second_frame,text=start_time[11:],width=115,font=('Tahoma',15),fg='black',bg='#aaaaaa').grid(row=x,column=0,columnspan=2)
                    x += 1
                    for j in result1:
                        temp = int(j[2]) * int(j[3])
                        # print(j[0][11:],j[1],j[2],j[3],temp)
                        sub_total += temp
                        total_pts += temp
                        e1=Label(second_frame,text=j[0][11:],12),bg='#dcdcdc',width=71)
                        e1.grid(row=x,column=0)

                        e2=Label(second_frame,text=str(j[1]),width=71)
                        e2.grid(row=x,column=1)
                        e1.bind('<Enter>',on_click)
                        e1.bind('<Leave>',on_leave)
                        e2.bind('<Enter>',on_click)
                        e2.bind('<Leave>',on_leave)
                        x += 1

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)