我正在尝试将LoginWindow
和mainWindow
分成不同的模块/文件。我首先在我的mainWindow
中创建了一个名为bgWindow
的函数,以避免关闭应用程序并在文件中调用该函数。在完成loginWindow
的代码时,我遇到的一个问题是弄清楚一旦用户成功从login_user函数登录而又不引起循环依赖的情况下如何打开主窗口。
我确实尝试使用from mainWindow import mainScreen
,但这会导致另一个mainLoop()
。
mainWindow.py
:
def mainWindow():
print("Go to main Window")
def bgWindow():
screen = tk.Tk()
width = 1024
height = 620
screen.title("Inventory Management System")
screen_width = screen.winfo_screenwidth()
screen_height = screen.winfo_screenheight()
x = (screen_width/2) - (width/2)#adjust width by 2
y = (screen_height/2) - (height/2)
screen.geometry("%dx%d+%d+%d" % (width, height, x, y))
screen.resizable(0, 0)
screen.config(bg="#98BDF0")
label1 = tk.Label(text = "Welcome to the Simple Inventory Management System", width = "300", height="2", bg = "#6a84a8", font = ('Calibri', 20))
label1.pack()
screen.after(250, startupWindow)
screen.mainloop()
bgWindow()
loginWindow.py
:
import mainWindow
def login_user():
userLogInfo = logUsername.get()
passLogInfo = logPassword.get()
cursor.execute("SELECT * FROM employeeUser WHERE username = ? and password = ?",(userLogInfo, passLogInfo))
loginUser = cursor.fetchone()
if userLogInfo == "" or passLogInfo == "":
lblResultLog.config(text="Please fill in the entire field!", fg="red")
```
elif loginUser is not None:
print("Login Success")
loginScr.destroy()
startupScreen.destroy()
mainWindow.mainWindow()
```
else:
lblResultLog.config(text="Invalid username or password!", fg="red")
logUsername.set("")
logPassword.set("")