1 回答

TA貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超6個(gè)贊
我在這里看到兩個(gè)問(wèn)題,第一個(gè)問(wèn)題是您嘗試用于.grid顯示文本的標(biāo)簽,并用于.pack滾動(dòng)條。您不能在同一窗口中同時(shí)使用.grid和。.pack
.grid(row=index, column=0)這是我通過(guò)替換來(lái)糾正此問(wèn)題的代碼.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()
第二個(gè)問(wèn)題是滾動(dòng)條實(shí)際上沒(méi)有用。我不相信滾動(dòng)條本身就可以在 tkinter 中的窗口/框架上工作。這意味著修復(fù)原始問(wèn)題后,標(biāo)簽和滾動(dòng)條現(xiàn)在都會(huì)加載,但滾動(dòng)條不會(huì)執(zhí)行任何操作。
添加回答
舉報(bào)