Advertisement
here2share

# Tk_web_text_only.py

Sep 16th, 2017
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. # Tk_web_text_only.py
  2.  
  3. urlrep="http://webcache.googleusercontent.com/search?q=cache:###&num=1&hl=en&gl=ca&strip=1&vwsrc=0"
  4.  
  5. try:
  6.     # Python2
  7.     from Tkinter import *
  8.     from urllib2 import urlopen
  9. except ImportError:
  10.     # Python3
  11.     from tkinter import *
  12.     from urllib.request import urlopen
  13. import webbrowser
  14. import time
  15.  
  16. root=Tk()
  17. root.geometry('1280x64+0+0')
  18. root.title('Open URL as Text-Only')
  19.  
  20. topFrame=LabelFrame(root,text="",height=40)
  21. topFrame.pack(fill=X)
  22. topFrame.pack_propagate(False)
  23.  
  24. Frame2=LabelFrame(root,height=30,borderwidth=0,bg="aqua")
  25. Frame2.pack(fill=X)
  26. Frame2.pack_propagate(False)
  27.  
  28. ffff=Listbox(topFrame,selectmode=EXTENDED) # Bingo! Multiple links can be chosen, using the Shift and Control keyboard modifiers
  29. ffff.pack(fill=BOTH,expand=YES,side=LEFT)
  30.  
  31. #
  32. def from_clipboard():
  33.     html = root.clipboard_get()
  34.     url.set(html)
  35.     root.update()
  36.     opentab(html)
  37. #
  38. def text_only():
  39.     html=ent.get()
  40.     opentab(html)
  41. #
  42. def opentab(html):
  43.     if "%2F%2F" in html:
  44.         html=html.split("2F%2F")[-1]
  45.         html=html.split("&usg=")[0]
  46.         html=html.replace('%2F','/')
  47.     webbrowser.open(urlrep.replace('###',html))
  48.     time.sleep(0.5)
  49. #
  50.  
  51. btn=Button(Frame2,text="Enter URL",width=16,command=text_only)
  52. btn.pack(side=LEFT)
  53.  
  54. url=StringVar()
  55. ent=Entry(Frame2,width="180",textvariable=url)
  56. ent.pack(side=LEFT)
  57.  
  58. cpb=Button(Frame2,text="Clipboard",command=from_clipboard)
  59. cpb.pack(side=RIGHT)
  60.  
  61. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement