pyqt5 构建一个删除电脑凭据的gui程序

# _*_ coding: utf-8 _*_
__author__ = 'pythonwu'
__date__ = "2018/12/25 12:28"

import subprocess
import json
import sys
from PyQt5.QtWidgets import QApplication,QWidget,QLineEdit,QLabel,QTextEdit,QPushButton,QPlainTextEdit
from PyQt5.QtGui import QIcon
from PyQt5 import QtGui,QtCore


info = 'target='
cmdconsole = []
def popen(cmd):
try:
popen = subprocess.Popen(cmd,stdout=subprocess.PIPE)
popen.wait()
lines = popen.stdout.readlines()
return [line.decode('gbk') for line in lines]
except BaseException as e:
return -1


cmdpress = popen('cmdkey /list')
# print(cmdpress)
cmdformate = []

for i in range(len(cmdpress)-1,-1,-1):
if cmdpress[i] == ' ':
cmdpress.remove(' ')
for j in cmdpress:
# print(j)
j.strip()
cmdformate.append(j.strip())

# print(cmdformate)
for i in range(len(cmdformate)-1,-1,-1):
if cmdformate[i] == '':
cmdformate.remove('')
print(cmdformate)

for i in cmdformate:
if i.find(info)== -1:
pass
else:
cmdconsole.append(i[i.find(info)+7:])
print(cmdconsole)
cmdstr = str()
for i in cmdconsole:
cmdstr +=i+' '

class Example(QWidget):

def __init__(self):
super(Example, self).__init__()
# self.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint)
self.setWindowFlags(QtCore.Qt.WindowCloseButtonHint)
self.initUI()


def initUI(self):

self.lbl = QLabel(self)
labelEnd = QLabel(self)
qle = QPlainTextEdit(self)
btAdd = QPushButton('添加',self)
btDelOne = QPushButton('删除',self)
btDelAll = QPushButton('清空',self)
btBackup = QPushButton('备份',self)
btReback = QPushButton('还原',self)
btClose = QPushButton('关闭',self)

qle.move(18,80)
qle.resize(319,224)
qle.setPlainText(cmdstr)
qle.setReadOnly(True)
qle.setMouseTracking(True)

btAdd.move(350,80)
btDelOne.move(350,120)
btDelAll.move(350,160)
btBackup.move(18,470)
btReback.move(200,470)
btClose.move(350,470)

labelEnd.move(18,358)
labelEnd.setText('使用说明: 添加:新增凭据 删除:单个删除 清空:删除所有凭据 ')
self.lbl.move(18,29)
self.lbl.setText("Windows 可以存储服务器、网站和程序的登陆凭据。当重新访问其中任何一个 地方时,Windows将尝试让你自动登陆。")
self.setStyleSheet("QLabel{font-size:12px;font-weight:normal;font-family:Arial;}")
self.resize(456,512)
self.setWindowTitle('存储的用户名和密码')

self.show()




if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())

# for i in cmdpress:
# i.lstrip()
# cmdformate.extend(i)
# print(cmdformate)


# c = ['1','3','5','5']
# for i in range(len(c)-1,-1,-1):
# if c[i] == '1':
# c.pop(i)
# print(c)

# i = []
# c = [' 1 222 2 ','3','5','5']
# for l in c:
# l.strip()
# print(i)


效果图:

代码草稿,看情况放重写后的代码
原文地址:https://www.cnblogs.com/wudeng/p/10175889.html