Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Uninstall pip packages GUI
- By Steve Shambles Oct 2019
- stevepython.wordpress.com
- source: based on an idea from
- https://github.com/GDGVIT/pip-gui/blob/master/pip_gui/Package_Management/installedList.py
- """
- import subprocess
- from subprocess import getoutput
- from tkinter import Tk, Button, LabelFrame, messagebox, N, E, W, S
- from tkinter.ttk import Combobox
- class Pun():
- """Global store"""
- installedPackages = ""
- frame0 = None
- combo1 = None
- # Build GUI frame
- root = Tk()
- root.title('UnPackage')
- Pun.frame0 = LabelFrame(root, text="Pip installed packages")
- Pun.frame0.grid(padx=8, pady=8, row=0, column=0)
- def clkd_uninstall():
- '''uninstall button was clicked'''
- pckg = Pun.combo1.get()
- quest = messagebox.askyesno('Question', 'Are you sure you want to uninstall\n'+str(pckg))
- if quest:
- ex = "pip uninstall"+" "+str(pckg)
- subprocess.Popen(ex)
- def get_pips():
- """Get pip installed packages int oa combo list"""
- packages = getoutput('pip freeze')#change to pip3 freeze if required
- Pun.installedPackages = [i.split('==')[0] for i in packages.split('\n')]
- Pun.installedPackages = [i for i in Pun.installedPackages if ' ' not in i]
- #combo box
- Pun.combo1 = Combobox(Pun.frame0)
- Pun.combo1['values'] = (Pun.installedPackages)
- Pun.combo1.current(0)
- Pun.combo1.grid(padx=5, pady=5, row=0, column=0)
- #start
- get_pips()
- #buttons
- btn1 = Button(Pun.frame0, bg='skyblue', text='Uninstall selected package', command=clkd_uninstall)
- btn1.grid(pady=5, padx=5, row=1, column=0, sticky=N+E+W+S)
- btn2 = Button(Pun.frame0, bg='springgreen', text='Refresh package list', command=get_pips)
- btn2.grid(pady=5, padx=5, row=2, column=0, sticky=N+E+W+S)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement