Python Forum
GUI list of installed packages
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GUI list of installed packages
#1
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]
#2
Have you considered using pip freeze for the file dump?
Running Manjaro Linux 16.08/OpenRC/i3wm on a Dell Precision 5510.

John 3:17
#3
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)


Possibly Related Threads…
Thread Author Replies Views Last Post
  List all installed TeX packages in Linux Gribouillis 2 2,076 Jul-20-2020, 10:04 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020