Advertisement
here2share

# Tk_PowerSearch.py

Oct 22nd, 2020 (edited)
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.53 KB | None | 0 0
  1. # Tk_PowerSearch.py
  2.  
  3. try:
  4.     from Tkinter import *
  5. except:
  6.     from tkinter import *
  7. import re
  8. import tempfile
  9. import webbrowser
  10.  
  11. srcfilename=tempfile.mktemp(".html", "demo_")
  12. web="""<!DOCTYPE html><b>@"""
  13.  
  14. root = Tk()
  15. ww = root.winfo_screenwidth()
  16. hh = root.winfo_screenheight()
  17. root.geometry(str(ww)+"x"+str(hh)+"+-7+0") # to hide the frame
  18. root.title('Tk PowerSearch')
  19.  
  20. zw,zh = 124,27
  21. cvw = int(ww/zw)
  22. cvh = int(hh/zh)
  23. bg_gray = 'gray94'
  24. btnBg = '@ lightgreen lightpink lightblue'.replace('@',bg_gray).split()
  25.  
  26. def show_results():
  27.     sites = SITES[:]
  28.     L = range(len(sites))
  29.     t = [[] for z in L]
  30.     i = 0
  31.     while i in btn:
  32.         s = btn[i]['text']
  33.         for j in L:
  34.             k = [0,1,2,3][btn[i,BG]]
  35.             if k:
  36.                 if '::' in sites[j]:
  37.                     sites[j],ttt = sites[j].split('::')
  38.                     t[j] += [s.replace('@',ttt.split()[k-1])]
  39.                 elif k == 1:
  40.                     t[j] += ['"'+s+'"']
  41.                 elif k == 2:
  42.                     t[j] += ['-'+s]
  43.                 elif k == 3:
  44.                     t[j] += [s]
  45.         i += 1
  46.     ttt = ['+'.join(t[i]) for i in L]
  47.     for i in L:
  48.         a,b = sites[i].split('@')
  49.         ttt[i] = a+ttt[i]+b
  50.    
  51.     links = []
  52.     for t in ttt:
  53.         if t: links.append("<a href='"+t+"'target='_blank'>"+t[:160]+"...</a>")
  54.     if links:
  55.         links = '<br><br>'.join(links)
  56.         temp = open(srcfilename, 'w')
  57.         temp.write(web.replace('@',links))
  58.         temp.close()
  59.         webbrowser.open_new_tab(srcfilename)
  60.  
  61. def values(i):
  62.     btn[i,BG] = [1,2,3,0][btn[i,BG]]
  63.     btn[i].config(bg=btnBg[btn[i,BG]])
  64.  
  65. btn = {}
  66. BG = 'bg'
  67. yyy = 'tkinter pil math random'.split()
  68. zzz = 'stackoverflow'.split()
  69. nnn = 'numpy pygame pyqt java js javascript matplotlib pyplot wxpython'.split()
  70. ttt = 'game android'
  71.  
  72. def refresh():
  73.     i = 0
  74.     t = search.get().split()
  75.     y,n,z = yyy[:],nnn[:],zzz[:]
  76.     for h in range(1,cvh-4):
  77.         for w in range(cvw):
  78.             activation = 0
  79.             if t:
  80.                 s = t.pop(0)
  81.                 activation = 1
  82.             elif y:
  83.                 s = y.pop(0)
  84.                 activation = 3
  85.             elif n:
  86.                 s = n.pop(0)
  87.                 activation = 2
  88.             elif z:
  89.                 s = z.pop(0)
  90.             else:
  91.                 s = str(i)
  92.             btn[i] = Button(root, text=s, command=lambda iii=i:values(iii), relief=GROOVE, width=16, anchor='nw')
  93.             btn[i].place(x=2+w*zw, y=40+h*zh)
  94.             btn[i,BG] = max(0,activation-1)
  95.             if activation:
  96.                 values(i)
  97.             i += 1
  98.  
  99. search = StringVar()
  100. Entry(root, text=search, width=120).grid(sticky='we',row=0,column=3,columnspan=60)
  101. search.set(ttt)
  102. Button(root, text='Refresh', command=refresh).grid(sticky='we',row=0,column=1,columnspan=1)
  103. Button(root, text='Show Results', command=show_results).grid(sticky='we',row=0,column=2)
  104. refresh()
  105.  
  106. SITES = '''
  107. https://github.com/search?l=python&q=@&type=repositories
  108. https://www.google.com/search?q=@
  109. https://duckduckgo.com/?q=@&t=h_&ia=web
  110. https://www.bing.com/search?q=@
  111. https://search.yahoo.com/search;_ylt=?fr2=sb-top-search&q=@&fr=sfp&iscqry=
  112. https://www.yandex.com/search/?text=@&lr=10000
  113. https://www.startpage.com/search?q=@
  114. https://gibiru.com/results.html?q=@
  115. https://twitter.com/search?q=@&src=typed_query
  116. https://www.ask.com/web?q=@&qsrc=178&qo=hpSearchSuggestions&o=0&l=dir
  117. https://results.excite.com/serp?q=@
  118. https://www.webcrawler.com/search?q=@
  119. https://www.answers.com/search?q=@
  120. https://www.ehow.com/search?q=@
  121. https://www.quora.com/search?q=@
  122. https://www.wikihow.com/wikiHowTo?search=@
  123. https://stackoverflow.com/search?tab=votes&q=@
  124. https://www.askpython.com/?s=@
  125. https://riptutorial.com/topic?q=@
  126. https://tkdocs.com/search.html?q=@
  127. https://www.activestate.com/?s=@
  128. https://realpython.com/search?q=@
  129. https://www.blog.pythonlibrary.org/?s=@
  130. https://www.python.org/search/?q=@+&submit=
  131. https://docs.python.org/3/search.html?q=@+&check_keywords=yes&area=default
  132. '''.strip().splitlines()
  133.  
  134. EXT_SITES = '''
  135. https://www.w3schools.com
  136. https://www.pythonware.com
  137. https://www.pythoncentral.io
  138. https://www.w3resource.com/python/python-tutorial.php
  139. https://repl.it/languages/tkinter
  140. https://pythonbasics.org/tkinter
  141. https://www.scripps.edu/sanner/python/inputform/tkinterWidgets.html
  142. https://www.kite.com/python/docs/tkinter
  143. https://www.dummies.com/programming/python/using-tkinter-widgets-in-python
  144. https://riptutorial.com/tkinter
  145. http://zetcode.com/tkinter
  146. https://www.cs.mcgill.ca/~hv/classes/MS/TkinterPres
  147. https://www.javatpoint.com/python-tkinter
  148. https://www.geeksforgeeks.org/python-gui-tkinter
  149. https://www.python-course.eu/python_tkinter.php
  150. http://effbot.org/tkinterbook
  151. https://www.tutorialspoint.com/python/python_gui_programming.htm
  152. https://www.datacamp.com/community/tutorials/gui-tkinter-python
  153. https://realpython.com/python-gui-tkinter
  154. https://wiki.python.org/moin/TkInter
  155. '''.strip().splitlines()
  156.  
  157. root.mainloop()
  158.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement