我是 python 新手,我试图用 Tkinter 做一个简单的程序。我想删除 GUI 元素“错误”和“密码文本”。但我不知道该怎么做。我很想得到一些帮助,感谢阅读!
from tkinter import *
import os
import string
import random
window = Tk()
window.title("Password Generator")
window.configure(background="white")
def click():
global length
length = textEntry.get()
start()
def start():
global length
lower = string.ascii_lowercase
upper = string.ascii_uppercase
digits = string.digits
symbols = string.punctuation
all = lower + upper + digits + symbols
try:
global randomPass
randomPass = random.sample(all, int(length))
password = "".join(randomPass)
global passwordText
passwordText = Label (window, text=password, bg="white", fg="black", font="none 12 bold") .grid(row=3, column=0, sticky=W)
return
except:
error = Label (window, text="Error, please try another length", bg="white", fg="black", font="none 12 bold") .grid(row=4, column=0, sticky=W)
textEntry = Entry(window, width=60, bg="white")
textEntry.grid(row=1, column=0, sticky=W)
Button(window, text="Submit Length", width=13, command=click) .grid(row=2, column=0, sticky=W)
window.mainloop()