可点击的 Tkinter 标签 [英] Clickable Tkinter labels
本文介绍了可点击的 Tkinter 标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将使用代表 URL 的标签列表填充框架.url 将从列表中输入,数量可以在 3 到 5 之间,由用户决定.使这些 url 可点击的最简单方法是什么,以便用户可以访问显示的网站?还有比使用标签更好的方法吗?
I will be populating a frame with a list of labels representing URLs. The url's will be fed in from a list and can be between 3 and 5 in number, decided by user. What is the easiest way to make these url's clickable, so the user can get to the website displayed? Is there a better way to do this than use labels?
谢谢
推荐答案
我认为标签很好.您只需要将回调绑定到鼠标点击即可.
Labels are fine I think. You just need to bind a callback to a mouse click.
def open_url(url):
pass #Open the url in a browser
for i,url in enumerate(url_list):
label=tk.Label(frame,text=url)
label.grid(row=i)
label.bind("<Button-1>",lambda e,url=url:open_url(url))
这篇关于可点击的 Tkinter 标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文