![]() |
|
GUI list of installed packages - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: Code sharing (https://python-forum.io/forum-5.html) +--- Thread: GUI list of installed packages (/thread-393.html) |
GUI list of installed packages - Larz60+ - Oct-09-2016 Hello, I had this posted on python-forum.org. It's a simple tkinter list of installed packages and version numbers import tkinter.tix as tk
import tkinter.filedialog as tf
import pip
class GetPackages:
def __init__(self, parent):
self.w = parent
self.bgc1 = '#ffffe5'
self.bgc2 = 'Lavender'
self.bgc3 = ' LightCyan'
self.pkglist = None
self.w.geometry('400x400+10+10')
self.w.title("Larz60+ Python Package List")
self.process_data()
def get_pkgs_from_pip(self):
self.pkglist = pip.get_installed_distributions()
def process_data(self):
w = self.w
# Get Package list
self.get_pkgs_from_pip()
t1 = tk.Text(w, wrap=tk.WORD, undo=0, bg=self.bgc1)
t1.pack(expand=1, fill=tk.BOTH)
t1scroll = tk.Scrollbar(t1)
t1.configure(yscrollcommand=t1scroll.set)
t1scroll.config(command=t1.yview)
t1scroll.pack(side=tk.RIGHT, fill=tk.Y)
b1 = tk.Button(w, text='Save', command=self.save_results)
b1.pack(side=tk.BOTTOM)
t1.insert(tk.END, "{Package Name} -- {Version Info}\n\n")
for item in self.pkglist:
t1.insert(tk.END, " {} -- {}\n".format(item.key, item.version))
def save_results(self):
filename = tf.asksaveasfilename()
with open(filename, 'w') as f:
for item in self.pkglist:
f.write('{},{}\n'.format(item.key, item.version))
if __name__ == '__main__':
root = tk.Tk()
GetPackages(root)
root.mainloop()[attachment=27]
RE: GUI list of installed packages - pydsigner - Oct-09-2016 Have you considered using pip freeze for the file dump? RE: GUI list of installed packages - Larz60+ - Oct-10-2016 No, saving was an afterthought. I'll leave that up to the user or if you wish, add it as an option (but leave the current save as well) |