1 回答
TA贡献1816条经验 获得超6个赞
我在这里看到两个问题,第一个问题是您尝试用于.grid显示文本的标签,并用于.pack滚动条。您不能在同一窗口中同时使用.grid和。.pack
.grid(row=index, column=0)这是我通过替换来纠正此问题的代码.pack(anchor = W)
from tkinter import *
from functools import partial
words = ["test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test"]
def validateLogin(password):
print(password.get())
if password.get() == "test":
newWindow = Tk()
newWindow.geometry('1800x800')
newWindow.title("Passwords")
scrollbar = Scrollbar(newWindow)
scrollbar.pack(side=RIGHT, fill=Y)
tkWindow.destroy()
for index, word in enumerate(words):
Label(newWindow, text=word).pack(anchor = W)
if password.get() != "test":
Label(tkWindow, text="Wrong password!", fg='red').grid(row=5, column=2)
#window
tkWindow = Tk()
tkWindow.geometry('250x100')
tkWindow.title('Passwords')
#password label and password entry box
passwordLabel = Label(tkWindow,text="Password").grid(row=1, column=0)
password = StringVar()
passwordEntry = Entry(tkWindow, textvariable=password, show='*').grid(row=1, column=2)
validateLogin = partial(validateLogin, password)
#login button
loginButton = Button(tkWindow, text="Login", command=validateLogin).grid(row=4, column=2)
tkWindow.mainloop()
第二个问题是滚动条实际上没有用。我不相信滚动条本身就可以在 tkinter 中的窗口/框架上工作。这意味着修复原始问题后,标签和滚动条现在都会加载,但滚动条不会执行任何操作。
添加回答
举报