簡體   English   中英

他們為我的代碼提供了這種類型錯誤“序列項 0:預期的 str 實例,未找到 NoneType”

[英]They give me this type error "sequence item 0: expected str instance, NoneType found" for my codes

from tkinter import*
import string
import random

win = Tk()
win.geometry("500x400")
win.title("password generator")

def password_generator():
    character = list(string.ascii_letters + string.digits + "@#$&^!%")
    random.shuffle(character)
    
    password =[]
    password_length = 7
    
    for x in range(password_length):
        password.append(random.shuffle(character))
        
    random.shuffle(password)
    password= "".join(password)
    pass_word_l.configure(password)
    

u_name = Label(win, text="Usename:", font="arial,20").place(x=70, y=100)
pass_word = Label(win, text="Password:", font="arial,20").place(x=70, y=160)

u_name_e = Entry(win, width=30).place(x=170, y=100)
pass_word_l = Label(win, font=("arial", 13,"bold")).place(x=170, y=160)

G_pass = Button(win, text="Generate Password", width=20, borderwidth=5, command=password_generator).place(x=190,y=220 )

win.mainloop()

我嘗試創建一個密碼生成器,但是當我運行代碼時,他們給了我這種類型的錯誤:“序列項 0:預期的 str 實例,未找到 NoneType”,我無法識別我的錯誤

你收到一個錯誤。 因為您在第 21 行的配置中遺漏了關鍵字text=from 。我包括來自@John Gordon 的評論。

from tkinter import*
import string
import random

win = Tk()
win.geometry("500x400")
win.title("password generator")

def password_generator():
    character = list(string.ascii_letters + string.digits + "@#$&^!%")
    random.shuffle(character)
    
    password =[]
    password_length = 7
    
    for x in range(password_length):
        password.append(random.choice(character))
        
    random.shuffle(password)
    password= "".join(password)
    pass_word_l.configure(text=password)
    

u_name = Label(win, text="Usename:", font="arial,20").place(x=70, y=100)
pass_word = Label(win, text="Password:", font="arial,20").place(x=70, y=160)

u_name_e = Entry(win, width=30).place(x=170, y=100)
pass_word_l = Label(win, font=("arial", 13,"bold"))
pass_word_l.place(x=170, y=160)

G_pass = Button(win, text="Generate Password", width=20, borderwidth=5, command=password_generator).place(x=190,y=220 )

win.mainloop()

截屏:

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM