from tkinter import * from tkinter import ttk import re from tem_pip import runpip # following structure that was recommended on http://stackoverflow.com/questions/17466561/best-way-to-structure-a-tkinter-application # I also review the code from https://gist.github.com/mikofski/5851633 about how to type clean the notebook app code class PIP_INTERFACE(Frame): def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent self.parent.title("PIP Package Manager") self._create_panel() def _create_panel(self): nb = ttk.Notebook(self.parent, name="notebook") nb.pack(fill=BOTH, expand=Y, padx=2, pady=3) self._create_search_tab(nb) # I can make more tab function here def _create_search_tab(self, nb): # frame to hold content """ Function for searching tab """ frame = Frame(nb, name="search") search_text = StringVar() ttk.Entry(frame, width=10, textvariable=search_text).grid(column=1, row=1, columnspan=2, sticky=W+E) sr_scroll = ttk.Scrollbar(frame, orient=VERTICAL) sr_scroll.grid(column=1, row=2, sticky=S+E) search_return = Listbox(frame, height=10, bg="black", fg="white", yscrollcommand=sr_scroll) search_return.grid(column=0, row=2, columnspan=2, rowspan=10, sticky=N+W+S+E) search_button = ttk.Button(frame, text="Search", command=lambda: self.search_package(search_text, search_return)) search_button.grid(column=3, row=1, sticky=W) search_information = Text(frame, width=20, height=10) search_information.insert(1.0, "This box will later use 'pip show package_name' to show the information") search_information.grid(column=2, row=2, columnspan=2, rowspan=10, sticky=N+W+S+E) install_button = Button(frame, text="Install")#command = self.install_package install_button.grid(column=2, row=12, sticky=N+W+E+S) uninstall_button = Button(frame, text="Uninstall")#command = self.uninstall_package uninstall_button.grid(column=3, row=12, sticky=N+W+E+S) nb.add(frame, text="Seach Package") def search_package(self, package_name, listbox): """ run the search and update the list box """ status, out, err = runpip("search {}".format(package_name.get())) # only extract the search package name and its version pattern = re.compile("(\w+.*?\(.*?\))") out_to_package_name = pattern.findall(out) if listbox is None: for i in range(0, len(out_to_package_name)): listbox.insert(i, out_to_package_name[i]) else: listbox.delete(0, END) for i in range(0, len(out_to_package_name)): listbox.insert(i, out_to_package_name[i]) if __name__ == "__main__": root = Tk() PIP_INTERFACE(root) root.mainloop()