Advertisement
steve-shambles-2109

Uninstall pip packages GUI

Oct 17th, 2019
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. """
  2. Uninstall pip packages GUI
  3. By Steve Shambles Oct 2019
  4. stevepython.wordpress.com
  5.  
  6. source: based on an idea from
  7. https://github.com/GDGVIT/pip-gui/blob/master/pip_gui/Package_Management/installedList.py
  8. """
  9. import subprocess
  10. from subprocess import getoutput
  11. from tkinter import Tk, Button, LabelFrame, messagebox, N, E, W, S
  12. from tkinter.ttk import Combobox
  13.  
  14. class Pun():
  15.     """Global store"""
  16.     installedPackages = ""
  17.     frame0 = None
  18.     combo1 = None
  19.  
  20. # Build GUI frame
  21. root = Tk()
  22. root.title('UnPackage')
  23. Pun.frame0 = LabelFrame(root, text="Pip installed packages")
  24. Pun.frame0.grid(padx=8, pady=8, row=0, column=0)
  25.  
  26. def clkd_uninstall():
  27.     '''uninstall button was clicked'''
  28.     pckg = Pun.combo1.get()
  29.     quest = messagebox.askyesno('Question', 'Are you sure you want to uninstall\n'+str(pckg))
  30.     if quest:
  31.         ex = "pip uninstall"+" "+str(pckg)
  32.         subprocess.Popen(ex)
  33.  
  34. def get_pips():
  35.     """Get pip installed packages int oa combo list"""
  36.     packages = getoutput('pip freeze')#change to pip3 freeze if required
  37.     Pun.installedPackages = [i.split('==')[0] for i in packages.split('\n')]
  38.     Pun.installedPackages = [i for i in Pun.installedPackages if ' ' not in i]
  39.     #combo box
  40.     Pun.combo1 = Combobox(Pun.frame0)
  41.     Pun.combo1['values'] = (Pun.installedPackages)
  42.     Pun.combo1.current(0)
  43.     Pun.combo1.grid(padx=5, pady=5, row=0, column=0)
  44.  
  45. #start
  46. get_pips()
  47.  
  48. #buttons
  49. btn1 = Button(Pun.frame0, bg='skyblue', text='Uninstall selected package', command=clkd_uninstall)
  50. btn1.grid(pady=5, padx=5, row=1, column=0, sticky=N+E+W+S)
  51. btn2 = Button(Pun.frame0, bg='springgreen', text='Refresh package list', command=get_pips)
  52. btn2.grid(pady=5, padx=5, row=2, column=0, sticky=N+E+W+S)
  53.  
  54. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement