Create a webpage that has an image that opens a page with the Wikipedia website when clicked. Refer to the sample below for clarification.
Note: When inserting the link to your image into your code, be sure to use the full URL, including https:// at the start of the URL.
# A simple example create webpage and write local comp
# and opening it in a browser
import webbrowser
# Important Replace the link to the picture with your own
# "https://imgur.com/a/I8rnv45" -
html= f"""
<!DOCTYPE html>
<html lang="en">
<head>
<title>A simple HTML document</title>
</head>
<body>
<p>Test example<p>
<img src="https://imgur.com/a/I8rnv45" onclick="window.open('https://www.wikipedia.org/', '_blank')">
</body>
</html>
"""
# file write
file_name = "example.html"
with open(file_name, "w") as file:
file.write(html)
# open in browser
webbrowser.open(file_name)
Comments
Leave a comment