请问tkinter中绑定事件函数怎么传参
在tkinter中定义了事件,然后绑定事件时调用函数,此时函数需要一个event参数,但是如果我还想往这个函数里传参,系统就要我定义event,请问此时我该怎么传参,代码如下import tkinter as tkfrom tkinter import *
def open_url(url,event):
webbrowser.open(url, new=0)
window = tk.Tk()
window.geometry('400x400')
tk.Frame(window,relief='groove',bd = 1).pack()
new = tk.Label(window,text = f' No.1 ',
width = 25,height =1)
new.place(x=50,y=50,anchor=NW)
new.bind("<Button-1>", open_url(url = 'https://tophub.today/'))
window.mainloop() 使用lambda匿名函数
在把15行改成new.bind("<Button-1>", lambda event: open_url(url = 'https://tophub.today/', event=event))
页:
[1]