【发布时间】:2022-07-15 17:31:11
【问题描述】:
我正在制作密码生成器。我想用 tkinter 做一个程序。当您按下按钮时,文本应更改为生成的随机密码,但它不起作用
有人可以帮我解决这个问题吗?
'''
将 tkinter 导入为 tk
随机导入
进口时间
将 tkinter.font 导入为字体
a = ['a','b','c','d','e','f','g','h','i','j','k','m' ,'n','o','p','q','r','s','t','u','v','w','x','y',' z']
b = ['A','B','C','D','E','F','G','H','I','J','K','M' 、'N'、'O'、'P'、'Q'、'R'、'S'、'T'、'U'、'V'、'W'、'X'、'Y'、' Z']
c = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
d = ['!', '#']
root = tk.Tk()
root.title("Password Generator")
root.configure(bg='white')
root.geometry('300x100')
bf1 = font.Font(family='Helvetica', size=16, weight='bold')
bf2 = font.Font(family='Times', size= 24, weight='bold')
def changetext():
psw = ''.join(random.choice(a + b + c + d)for i in range (9))
#btn1 = tk.Button(root, text = 'button1', command=changetext)
#btn1.grid(row = 1, column = 2, padx = 5, pady = 5)
#button1 = tk.Label(root, text="Generate password")
#button1.grid(row = 1, column = 1, padx = 5, pady = 5)
label = tk.Label(root, text="Hello World!")
label.pack(pady=20)
button = tk.Button(root, text="Change the text", command=changetext)
button.pack()
root.mainloop()
'''
【问题讨论】:
标签: python tkinter button random label