我有一个带有登录功能的tkinter GUI,它应该根据文本文件中的行拉出一些不同的框架/顶级窗口小部件。
我使用嵌套的try / except函数的lower(else)部分来检查文本文件中是否存在某些行,以及如果它们不存在则该怎么做。 问题是,如果它执行嵌套尝试,它似乎也执行嵌套的除部分,拉出两个不同的Toplevel窗口而不是一个,我不太确定为什么它同时做......?
我在文本文件中不存在第5行时尝试使用该方法,并执行嵌套,除了正常。
谁能告诉我哪里出错?
def login(self):
global Users
username = self.user_entry.get()
pw = self.password_entry.get()
run.Current_User.set(username)
if (username, pw) in Users:
#does some stuff irrelevant to the problem
else:
os.getcwd()
os.chdir('C:\\Users\\Michael Sibille\\Desktop\\Duty Program Test Folder\\Employee Files')
os.chdir(username)
readfile = open('userdata.txt', 'r')
lines = readfile.readlines()
type = lines[2]
#at this point, there are 5 lines (0-4) in the text file.
try:
medical = lines[9]
if type.strip() == 'ADMIN':
main_window.switch_frame(self.master, Admin_Notebook)
self.after(500, self.destroy)
self.warn.config(text='Login Successful!', bg='lime green', justify='center')
else:
main_window.switch_frame(self.master, User_Notebook)
self.after(500, self.destroy)
self.warn.config(text='Login Successful!', bg='lime green', justify='center')
except:
try:
contact = lines[5]
main_window.switch_frame(self.master, Create_Profile)
med = Medical(self.master)
self.after(500, self.destroy)
self.warn.config(text='Login Successful!', bg='lime green', justify='center')
except:
main_window.switch_frame(self.master, Create_Profile)
nameemailphone = Name_Email_Phone(self.master)
self.after(500, self.destroy)
self.warn.config(text='Login Successful!', bg='lime green', justify='center')
else:
self.warn.config(text="Invalid Username or Password", fg="black", bg='red', justify ='center')