[英]Graphical Python Password Generator : tkinter
I'm trying to create a password generator using tkinter.我正在尝试使用 tkinter 创建密码生成器。 I did the non-graphical version, so I thought to make a graphical version.
我做了非图形版本,所以我想制作一个图形版本。 When I run it, they show this:
当我运行它时,它们会显示:
Traceback (most recent call last):
File "C:/Users/biswa/OneDrive/Documents/Python/Graphical Password Generator.py", line 20, in <module>
welcome_text=Label("Welcome to my graphical password generator" ,fg='red', bg='yellow')
File "C:\Users\biswa\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 3143, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "C:\Users\biswa\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 2561, in __init__
BaseWidget._setup(self, master, cnf)
File "C:\Users\biswa\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 2530, in _setup
self.tk = master.tk
AttributeError: 'str' object has no attribute 'tk'
Here is the code:这是代码:
symbols=['!','@','#','$','%','^','&','*','(',')','~','`']
numbers=[1,2,3,4,5,6,7,8,9,0]
words=['a','b','c','d','e''f','g','h','i','j','k','l','m','n','o','p']
from tkinter import *
def generate():
print((random.choice(numbers)+
random.choice(words)+random.choice(symbols)+
random.choice(numbers)+random.hhoice(words +
random.choice(words)+random.choice(numbers)+
random.choice(symbols)+random.choice(words)
screen=Tk()
screen.title("Graphical Password generator")
screen.geometry('400x400')
welcome_text=Label("Welcome to my graphical password generator" ,fg='red', bg='yellow')
welcome_text.pack
generate=Button(text='Generate', fg='red', bg='yellow', command=generate)
generate.place(x=30, y=40)
name_storage=StringVar()
name=Entry(textvariable=name_storage)
name.pack()
screen.mainloop()
I modified your code so that it works:我修改了您的代码以使其正常工作:
import random
from tkinter import *
symbols=['!','@','#','$','%','^','&','*','(',')','~','`']
numbers=[1,2,3,4,5,6,7,8,9,0]
words=['a','b','c','d','e''f','g','h','i','j','k','l','m','n','o','p']
def generate():
print(str(random.choice(numbers))+
random.choice(words)+
random.choice(symbols)+
str(random.choice(numbers))+
random.choice(words)+
random.choice(words)+
str(random.choice(numbers))+
random.choice(symbols)+
random.choice(words))
screen = Tk()
screen.title("Graphical Password generator")
screen.geometry('400x400')
welcome_text=Label(screen, text = "Welcome to my graphical password generator" ,fg='red', bg='yellow')
welcome_text.pack()
generate=Button(screen, text='Generate', fg='red', bg='yellow', command=generate)
generate.place(x=30, y=40)
name_storage=StringVar()
name=Entry(screen, textvariable=name_storage)
name.pack()
screen.mainloop()
Note: Tested in Python 3.7.7注意:在 Python 3.7.7 中测试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.