I am trying to create a python 3 program where it would show an index of websites that the user could press it and it would open.
I created the fucntion that would open the link when the user press the text, but the program is opening the link as soon as i open it.
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()
if i change the code to this, it would work correctly, but i want to be able to determine which website to open on the function
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()
For the ones with the same doubt, i have found the solution in another forum:
To the ones with the same doubt, i have discovered the solution on another forum:
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()