0
下面是代碼:爲什麼我的Tkinter Python代碼不能按我的預期工作?
from tkinter import *
def main():
pw = ''
passwordCorrect = False
window = Tk()
instructionLabel = Label(window,text='Enter your password:')
entryBox = Entry(window)
def checkPassword():
if entryBox.get() == 'password':
global passwordCorrect
passwordCorrect = True
confirmButton = Button(window,text='Confirm',command=checkPassword)
instructionLabel.pack()
entryBox.pack()
confirmButton.pack()
window.mainloop()
if passwordCorrect:
print('Access granted')
else:
print('Access denied')
main()
當我關閉窗口,我總是得到消息「拒絕訪問」(等待「訪問授予」),即使我輸入「密碼」進入輸入框,然後按按鈕。我錯過了什麼?多謝。
刪除'全局passwordCorrect'。 – stovfl
你在期待什麼? – gkubed