Python 3可点击文本问题

时间:2018-01-10 11:53:01

标签: python python-3.x tkinter

我正在尝试创建一个python 3程序,它会显示一个用户可以按下它的网站索引,它会打开。

我创建了一个功能,当用户按下文本时会打开链接,但程序打开后会立即打开链接。

def website(platform):
    if platform is "Google":
        webbrowser.open_new(r"http://www.google.com")
    if platform is "Youtube":
        webbrowser.open_new(r"http://www.youtube.com")


link_Google = Label(frame1,text='Website', fg="blue", cursor="hand2")
link_Google.bind("<Button-1>", website("Google"))
link_Google.pack()

如果我将代码更改为此,它将正常工作,但我希望能够确定在该功能上打开哪个网站

def website(event):
    webbrowser.open_new(r"http://www.google.com")

link_Google = Label(frame1,text='Website', fg="blue", cursor="hand2")
link_Google.bind("<Button-1>", website)
link_Google.pack()

对于那些有同样怀疑的人,我在另一个论坛找到了解决方案:

对于那些有同样怀疑的人,我在另一个论坛上发现了解决方案:

def website(event, platfrom):
    if platfrom is "Google":
        webbrowser.open_new(r"http://www.google.com")

link_google = Label(frame1,text='Website', fg="blue", cursor="hand2")
link_google.bind("<Button-1>", lambda event, platform="Google": website(event,platform))
link_google.pack()

0 个答案:

没有答案