Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_PowerSearch.py
- try:
- from Tkinter import *
- except:
- from tkinter import *
- import re
- import tempfile
- import webbrowser
- srcfilename=tempfile.mktemp(".html", "demo_")
- web="""<!DOCTYPE html><b>@"""
- root = Tk()
- ww = root.winfo_screenwidth()
- hh = root.winfo_screenheight()
- root.geometry(str(ww)+"x"+str(hh)+"+-7+0") # to hide the frame
- root.title('Tk PowerSearch')
- zw,zh = 124,27
- cvw = int(ww/zw)
- cvh = int(hh/zh)
- bg_gray = 'gray94'
- btnBg = '@ lightgreen lightpink lightblue'.replace('@',bg_gray).split()
- def show_results():
- sites = SITES[:]
- L = range(len(sites))
- t = [[] for z in L]
- i = 0
- while i in btn:
- s = btn[i]['text']
- for j in L:
- k = [0,1,2,3][btn[i,BG]]
- if k:
- if '::' in sites[j]:
- sites[j],ttt = sites[j].split('::')
- t[j] += [s.replace('@',ttt.split()[k-1])]
- elif k == 1:
- t[j] += ['"'+s+'"']
- elif k == 2:
- t[j] += ['-'+s]
- elif k == 3:
- t[j] += [s]
- i += 1
- ttt = ['+'.join(t[i]) for i in L]
- for i in L:
- a,b = sites[i].split('@')
- ttt[i] = a+ttt[i]+b
- links = []
- for t in ttt:
- if t: links.append("<a href='"+t+"'target='_blank'>"+t[:160]+"...</a>")
- if links:
- links = '<br><br>'.join(links)
- temp = open(srcfilename, 'w')
- temp.write(web.replace('@',links))
- temp.close()
- webbrowser.open_new_tab(srcfilename)
- def values(i):
- btn[i,BG] = [1,2,3,0][btn[i,BG]]
- btn[i].config(bg=btnBg[btn[i,BG]])
- btn = {}
- BG = 'bg'
- yyy = 'tkinter pil math random'.split()
- zzz = 'stackoverflow'.split()
- nnn = 'numpy pygame pyqt java js javascript matplotlib pyplot wxpython'.split()
- ttt = 'game android'
- def refresh():
- i = 0
- t = search.get().split()
- y,n,z = yyy[:],nnn[:],zzz[:]
- for h in range(1,cvh-4):
- for w in range(cvw):
- activation = 0
- if t:
- s = t.pop(0)
- activation = 1
- elif y:
- s = y.pop(0)
- activation = 3
- elif n:
- s = n.pop(0)
- activation = 2
- elif z:
- s = z.pop(0)
- else:
- s = str(i)
- btn[i] = Button(root, text=s, command=lambda iii=i:values(iii), relief=GROOVE, width=16, anchor='nw')
- btn[i].place(x=2+w*zw, y=40+h*zh)
- btn[i,BG] = max(0,activation-1)
- if activation:
- values(i)
- i += 1
- search = StringVar()
- Entry(root, text=search, width=120).grid(sticky='we',row=0,column=3,columnspan=60)
- search.set(ttt)
- Button(root, text='Refresh', command=refresh).grid(sticky='we',row=0,column=1,columnspan=1)
- Button(root, text='Show Results', command=show_results).grid(sticky='we',row=0,column=2)
- refresh()
- SITES = '''
- https://github.com/search?l=python&q=@&type=repositories
- https://www.google.com/search?q=@
- https://duckduckgo.com/?q=@&t=h_&ia=web
- https://www.bing.com/search?q=@
- https://search.yahoo.com/search;_ylt=?fr2=sb-top-search&q=@&fr=sfp&iscqry=
- https://www.yandex.com/search/?text=@&lr=10000
- https://www.startpage.com/search?q=@
- https://gibiru.com/results.html?q=@
- https://twitter.com/search?q=@&src=typed_query
- https://www.ask.com/web?q=@&qsrc=178&qo=hpSearchSuggestions&o=0&l=dir
- https://results.excite.com/serp?q=@
- https://www.webcrawler.com/search?q=@
- https://www.answers.com/search?q=@
- https://www.ehow.com/search?q=@
- https://www.quora.com/search?q=@
- https://www.wikihow.com/wikiHowTo?search=@
- https://stackoverflow.com/search?tab=votes&q=@
- https://www.askpython.com/?s=@
- https://riptutorial.com/topic?q=@
- https://tkdocs.com/search.html?q=@
- https://www.activestate.com/?s=@
- https://realpython.com/search?q=@
- https://www.blog.pythonlibrary.org/?s=@
- https://www.python.org/search/?q=@+&submit=
- https://docs.python.org/3/search.html?q=@+&check_keywords=yes&area=default
- '''.strip().splitlines()
- EXT_SITES = '''
- https://www.w3schools.com
- https://www.pythonware.com
- https://www.pythoncentral.io
- https://www.w3resource.com/python/python-tutorial.php
- https://repl.it/languages/tkinter
- https://pythonbasics.org/tkinter
- https://www.scripps.edu/sanner/python/inputform/tkinterWidgets.html
- https://www.kite.com/python/docs/tkinter
- https://www.dummies.com/programming/python/using-tkinter-widgets-in-python
- https://riptutorial.com/tkinter
- http://zetcode.com/tkinter
- https://www.cs.mcgill.ca/~hv/classes/MS/TkinterPres
- https://www.javatpoint.com/python-tkinter
- https://www.geeksforgeeks.org/python-gui-tkinter
- https://www.python-course.eu/python_tkinter.php
- http://effbot.org/tkinterbook
- https://www.tutorialspoint.com/python/python_gui_programming.htm
- https://www.datacamp.com/community/tutorials/gui-tkinter-python
- https://realpython.com/python-gui-tkinter
- https://wiki.python.org/moin/TkInter
- '''.strip().splitlines()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement