不想記密碼?密碼全設定成一樣擔心安全?用別人程式擔心密碼洩露?看完本部落格,開發一個屬於自己的密碼管理程式吧

我們用到的是python的wxPython介面庫包

先來看下成果介面:簡潔主題明確

 要想開發wxPython需要先下載對應包,開啟cmd執行下列程式碼

 pip install -U wxPython

進入IDE進行開發,程式碼如下,可以直接執行檢視

import wx
import os class My(wx.Frame): def __init__(self, parent, title):
super(My, self).__init__(parent, title=title, size=(600, 400))
panel = wx.Panel(self) self.searchCtrl = wx.TextCtrl(panel, pos=(150, 10), size=(300, 30), style=wx.TE_CENTER)
self.search = wx.Button(panel, label="查詢", pos=(460, 12))
self.search.Bind(wx.EVT_BUTTON, self.findAccount) self.label1 = wx.StaticText(panel, label="所屬", pos=(40, 80))
self.belong = wx.TextCtrl(panel, pos=(90, 76), size=(400, 30), style=wx.TE_LEFT) self.label2 = wx.StaticText(panel, label="賬號", pos=(40, 140))
self.account = wx.TextCtrl(panel, pos=(90, 136), size=(400, 30), style=wx.TE_LEFT) self.label3 = wx.StaticText(panel, label="密碼", pos=(40, 200))
self.password = wx.TextCtrl(panel, pos=(90, 196), size=(400, 30), style=wx.TE_LEFT) self.save = wx.Button(panel, label="儲存", pos=(90, 266), size=(80, 30))
self.save.Bind(wx.EVT_BUTTON, self.saveClicked) self.reset = wx.Button(panel, label="重新整理", pos=(250, 266), size=(80, 30))
self.reset.Bind(wx.EVT_BUTTON, self.clearClick) self.Centre()
self.Show()
self.Fit() # 儲存文字
def saveClicked(self, event):
belong = self.belong.GetValue()
account = self.account.GetValue()
password = self.password.GetValue()
if belong == "":
digLog("所屬不能為空", "錯誤資訊提示")
elif account == "":
digLog("賬號不能為空", "錯誤資訊提示")
elif password == "":
digLog("密碼不能為空", "錯誤資訊提示")
else:
result = alike(self.belong.GetValue())
if result:
digLog("該所屬已存在", "失敗資訊提示")
return
text = belong + "/" + account + "/" + password
with open(os.getcwd() + "\pass.txt", 'a+', encoding='utf-8') as f:
f.write("\n" + text)
digLog("儲存成功", "成功資訊提示")
self.save.Enable(False) # 重新整理
def clearClick(self, event):
self.searchCtrl.Clear()
self.belong.Clear()
self.account.Clear()
self.password.Clear()
self.save.Enable(True) # 讀取文字
def findAccount(self, event):
target = self.searchCtrl.GetValue()
if target == "":
digLog("輸入框不能為空", "失敗資訊提示")
return
with open(os.getcwd() + "\pass.txt", 'a+', encoding='utf-8') as f: # 從TXT檔案中讀出資料
for line1 in f:
if target in line1.split("/")[0]: # 是否包含文字
self.belong.SetValue(line1.split("/")[0])
self.account.SetValue(line1.split("/")[1])
self.password.SetValue(line1.split("/")[2])
digLog("查詢成功", "成功資訊提示")
self.save.Enable(False)
return
digLog("未查到", "失敗資訊提示")
return # 判斷新增的賬號是否存在
def alike(exist):
with open(os.getcwd() + "\pass.txt", 'a+', encoding='utf-8') as foo:
for line in foo.readlines():
if exist in line.split("/")[0]:
return True
else:
return False def digLog(msg, title):
toastone = wx.MessageDialog(None, msg, title, wx.YES_DEFAULT | wx.ICON_QUESTION)
if toastone.ShowModal() == wx.ID_YES: # 如果點選了提示框的確定按鈕
toastone.Destroy() # 則關閉提示框 app = wx.App()
My(None, "儲存密碼程式")
app.MainLoop()

測試沒問題後進行打包exe程式

打包需要用到一個庫,強烈建議使用 pip 線上安裝的方式來安裝 PyInstaller 模組,不要使用離線包的方式來安裝,因為 PyInstaller 模組還依賴其他模組,pip 在安裝 PyInstaller 模組時會先安裝它的依賴模組。

pip install pyinstaller

完成後進行打包,進入程式檔案目錄,開啟cmd

執行下列命令 (-F是在dist只生成exe檔案  -w是取消程式啟動的命令框,-n是指定程式名,-i是指定程式圖示 )

pyinstaller -F -w -n savePW -i .\ico.ico index.py

成功如下:

 生成的檔案在程式檔案的dist目錄下,告別繁瑣的密碼檔案吧