蟒蛇 |使用 Tkinter 的隨機密碼生成器

| | | | | |

讓我們創建一個簡單的應用程序,它可以使用 Python 模塊 import random import pyperclip from tkinter import * from tkinter.ttk import *

下面是實現:


# 生成隨機的 Python 程序
# 使用 Tkinter 模塊的密碼

導入 隨機

導入 pyperclip

from tkinter import *

from tkinter .ttk import *


# 計算密碼的函數

def low ():

entry.delete( 0 , END)


# 獲取密碼長度

長度 = var1.get()

= "abcdefghijklmnopqrstuvwxyz"

= <代碼類="string">"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

數字 = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^& * ()"

密碼 = " "

# 如果選擇強度低

if var.get() = = 1 :

for i in range ( 0 , 長度):

密碼 = 密碼 + random.choice (lower)

return 密碼


# 如果選擇的強度是中等

elif var.get() = = 0 :

for i in range ( 0 , l ength):

密碼 = 密碼 + 隨機。選擇(上)

return 密碼


# 如果選擇的力強

elif var.get() = = 3 :

for i in range ( 0 , length):

密碼 = 密碼 + random.choice (digits)

return 密碼

else :

print ( "請選擇一個選項" )

< br>


# 密碼生成函數

def generate():

password1 = 低()

entry.insert( 10 , password1)



# 複製密碼到剪貼板的函數

def copy1 ( ):

random_password = entry.get ()

pyperclip.copy (random_password)


# 主函數


# 創建 GUI 窗口

root = tk()

var = IntVar ()

var1 = IntVar ()


# 你的 GUI 窗口的標題

root.title ( "Random Password Generator" )


# 創建快捷方式並發布顯示
# 生成密碼

Random_password = 標籤(根,文本 = "密碼" )

Random_password.grid(row = 0 )

entry = Entry (root)

entry.grid(行 = 0 ,列 = 1 )


# 為密碼長度創建標籤

c_label = 標籤(根,文本 = "Length" )

c_label.grid (row = 1 )


# 創建不會復制的按鈕
# 將密碼複製到剪貼板並生成
# 這將生成密碼

copy_button = 按鈕( root, text = "複製" , command = copy1)

copy_button.grid (row = 0 ,列 = 2 )

generate_button <代碼類="keyword "> = 按鈕 (root, text = "Generate" , 命令 = generate)

generate_button .grid (row = 0 , column = 3 )


# 用於決策的單選按鈕
# 密碼強度
# 默認中等

radio_low = Radiobutton (root, text = "Low" ,變量 = <代碼類s = "plain"> var, value = 1 )

radio_low.grid(行=1 code> , column = 2 , 粘性 = ’E’ )

radio_middle = Radiobutton (root, text = "Medium" ,變量 = var, value = 0 )

radio_middle.grid (row = 1 ,列 = 3 ,粘性 = ’E’ )

radio_strong = Radiobutton (root, text = "Strong" , variable = var, value = 3 )

radio_strong.grid (行 = 1 ,列 = 4 , 粘性 = ’E’ )

combo = Combobox (root, textvariable code> = var1)


# 組合框為你的密碼長度

combo [ ’ values’ ] = ( 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ,

17 , 18 , 19 代碼> , 20 , 21 , 22 , 23 , 24 , 25 ,

26 , 27 , 28 , 29 , 30 , 31 , 32 , "Length" )

combo.current ( 0 )

combo.bind( ’< <<組合框選擇> >’ )

combo.grid (column = 1 , row = 1 )


# 啟動 GUI
root.mainloop ()

輸出:

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method