-2
這是一個簡單的GUI程序,用於檢查用戶是否輸入了正確的用戶名和密碼。問題是,即使輸入正確的用戶名和密碼,即管理和祕密,它仍然輸出「無效登錄」使用Python GUI的用戶名和密碼
這是代碼:
from tkinter import *
import tkinter.messagebox as box
def dialog1():
box.showinfo('info','Correct Login')
def dialog2():
box.showinfo('info','Invalid Login')
window = Tk()
window.title('Countries Generation')
frame = Frame(window)
Label1 = Label(window,text = 'Username:')
Label1.pack(padx=15,pady= 5)
entry1 = Entry(window,bd =5)
entry1.pack(padx=15, pady=5)
username = entry1.get()
Label2 = Label(window,text = 'Password: ')
Label2.pack(padx = 15,pady=6)
entry2 = Entry(window, bd=5)
entry2.pack(padx = 15,pady=7)
password = entry2.get()
if (username == 'admin' and password == 'secret'):
btn = Button(frame, text = 'Check Login',command = dialog1)
else:
btn = Button(frame, text ='Check Login', command = dialog2)
btn.pack(side = RIGHT , padx =5)
frame.pack(padx=100,pady = 19)
window.mainloop()
http://stackoverflow.com/questions/16525582/how-to-make-a-set-username-and-password-in-tkinter-python && http://stackoverflow.com/問題/ 28156719/how-can-i-integrate-tkinter-with-python-log-in-screen在這裏有一些例子可以告訴你如何去做。 – Lafexlos
任何和所有事件觸發的檢查都應該通過一個函數來完成。您的if語句在腳本啓動後運行,將該檢查移至一個按下按鈕時調用的函數。 –
謝謝你,你幫了很多 –