Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Create_HTML_links.py
- import re
- import tempfile
- import webbrowser
- try:
- # Python2
- from Tkinter import *
- from urllib2 import urlopen
- except ImportError:
- # Python3
- from tkinter import *
- from urllib.request import urlopen
- #
- srcfilename=tempfile.mktemp(".html", "demo_")
- root=Tk()
- root.geometry('500x40+0+0')
- root.title('Create HTML links')
- Frame3=LabelFrame(root,height=30,borderwidth=0)
- Frame3.pack(fill=X)
- Frame3.pack_propagate(False)
- ok='''<a href="@" target="_blank">@</a>''' # alt to target="_self"
- web="""<html>
- <head></head>
- <body>@</body>
- </html>"""
- urls=[]
- def cpbd():
- global urls
- urls=root.clipboard_get().split('\n')
- #
- def hyperlinks():
- global urls
- cpbd()
- t=[]
- for url in urls:
- url=url.strip()
- url=ok.replace('@',url)
- if url and url not in t: t.append(url)
- urls='<br>'.join(t)
- print urls
- temp=open(srcfilename, 'w')
- temp.write(web.replace('@',urls))
- temp.close()
- webbrowser.open_new_tab(srcfilename)
- #
- cpb=Button(Frame3,text="Links",width=16,command=hyperlinks)
- cpb.pack(side=LEFT)
- lbl=Label(Frame3)
- lbl.pack(side=LEFT)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement