如何在 tkinter 中搜索用户输入文件是否存在 python
how to search if user input file exist or not in tkinter python
我已经做到了,每当有人注册时,都会创建 txt 文件并以用户用户名命名。现在我正在尝试检查目录中是否存在用户名 txt 文件,这是我尝试过的代码。
我无法检查用户名 txt 文件是否存在。我尝试了很多不同的搜索方式 google 但没有运气,有些我在评论中提到过。请帮忙看看
def db():
a = (E1.get(), E2.get(), E3.get(),E4.get(),E5.get())
if "./library/"+E1.get() == os.path.isfile("./library/"+E1.get()):
# if E1.get() == os.path.isfile(E1.get()):
# if E1.get()in os.path.isdir("./library/"):
cur.execute("insert into Booking values(?,?,?,?,?)", a)
con.commit()
cur.execute("select * from Booking")
a = cur.fetchall()
ab = int(E4.get())
cost=100
ac = ab * cost
messagebox.showinfo("Congratulation!!", "Your oreder value is %s" % ac)
print(a)
te.destroy()
os.system("library.py")
else:
print("username invalid")
尝试替换下面的行
if "./library/"+E1.get() == os.path.isfile("./library/"+E1.get()):
与
if os.path.isfile("./library/"+E1.get()):
您可能对 os.path.isfile()
fn 的 return
值感到困惑。
我已经做到了,每当有人注册时,都会创建 txt 文件并以用户用户名命名。现在我正在尝试检查目录中是否存在用户名 txt 文件,这是我尝试过的代码。 我无法检查用户名 txt 文件是否存在。我尝试了很多不同的搜索方式 google 但没有运气,有些我在评论中提到过。请帮忙看看
def db():
a = (E1.get(), E2.get(), E3.get(),E4.get(),E5.get())
if "./library/"+E1.get() == os.path.isfile("./library/"+E1.get()):
# if E1.get() == os.path.isfile(E1.get()):
# if E1.get()in os.path.isdir("./library/"):
cur.execute("insert into Booking values(?,?,?,?,?)", a)
con.commit()
cur.execute("select * from Booking")
a = cur.fetchall()
ab = int(E4.get())
cost=100
ac = ab * cost
messagebox.showinfo("Congratulation!!", "Your oreder value is %s" % ac)
print(a)
te.destroy()
os.system("library.py")
else:
print("username invalid")
尝试替换下面的行
if "./library/"+E1.get() == os.path.isfile("./library/"+E1.get()):
与
if os.path.isfile("./library/"+E1.get()):
您可能对 os.path.isfile()
fn 的 return
值感到困惑。