Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Tạo Label có thể click trong Tkinter

Label hiển thị text/hình ảnh. Có thể biến Label thành hyperlink clickable bằng bind('', callback) mở trình duyệt.

Ví dụ

# Import thư viện
from tkinter import *
import webbrowser

# Tạo khung
win = Tk()
win.geometry("750x250")

# Callback mở web
def callback(url):
    webbrowser.open_new_tab(url)

# Tạo Label link
link = Label(win, text="www.tutorialspoint.com", font=('Helvetica', 15), fg="blue", cursor="hand2")
link.pack()
link.bind("", lambda e: callback("https://www.tutorialspoint.com"))

win.mainloop()

Kết quả

Label màu xanh, con trỏ hình bàn tay. Click mở trang web tutorialspoint.com.

Tạo Label có thể click trong Tkinter