python鼠标事件包括哪几种_python-在Tkinter中列出鼠标悬停事件函数

我正在将医疗工具的GUI制作为课程项目.给定条件后,它应输出从不同网站(如webMD)收集的一堆治疗选项.我希望能够处理任何列出的治疗方法的鼠标悬停事件,以提供有关该治疗方法的更多信息(例如,药物类别,是否为通用药物等).

标签存储在列表中,因为我不知道会预先返回多少种不同的处理方法.所以我的问题是如何使这些鼠标悬停事件起作用.我不能为每个可能的标签写一个函数定义,它们的数量可能成百上千.我敢肯定有一种非常Python的方式来做到这一点,但我不知道该怎么办.

这是我创建标签的代码:

def search_click():

"""

Builds the search results after the search button has been clicked

"""

self.output_frame.destroy() # Delete old results

build_output() # Rebuild output frames

treament_list = mockUpScript.queryConditions(self.condition_entry.get()) # Get treatment data

labels = []

frames = [self.onceFrame, self.twiceFrame, self.threeFrame, self.fourFrame] # holds the list of frames

for treament in treament_list: # For each treatment in the list

label = ttk.Label(frames[treament[1] - 1], text=treament[0]) # Build the label for treatment

labels.append(label) # Add the treatment to the list

label.pack()

这就是GUI的样子(不要判断[-;)

文本“将鼠标悬停在药物上以获得信息”应根据鼠标悬停在哪种药物上进行更改.

解决方法:

I can’t write a function definition for every single possible label, they would number in the hundreds or thousands. I’m sure there’s a very pythonic way to do it, but I have no idea what.

就您而言,类似:

def update_bottom_scroll_bar(text):

# whatever you want to do to update the text at the bottom

for treatment in treament_list: # For each treatment in the list

label = ttk.Label(frames[treatment[1] - 1], text=treatment[0]) # Build the label for treatment

label.bind("", lambda event, t=treatment: update_bottom_scroll_bar(text=t))

label.bind("", lambda event: update_bottom_scroll_bar(text='Default label text'))

labels.append(label) # Add the treatment to the list

label.pack()

还请正确拼写您的变量,我更正了治疗方法…

标签:mouseover,list,tkinter,python,user-interface

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值