[英]If Statement depending on the contents of a .txt file - Python 3.9
def change():
wind = Tk()...
text1 = Entry(wind)
text1.pack()
def write():
newfile = open("newfile.txt", "w")
newfile.write(text1.get())
newfile.close()
def show_password():
global r1
r1 = open("newfile.txt", "r")
print("Password is: %s" % r1.read())
btn2 = Button(wind, text="Show Password", command=show_password)
btn2.pack(pady=5)
btn1 = Button(wind, text="Set Password", command=write)
btn1.pack(pady=5)
def dark():
pop = Tk()...
e1 = Entry(pop, background="#292929", foreground="white")
e1.place(x=60, y=0)
e2 = Entry(pop, background="#292929", foreground="white")
e2.place(x=60, y=22)
def login():
global no1
username = (e1.get())
password = (e2.get())
print("Username: %s\nPassword: %s" % (e1.get(), e2.get()))
if username == "a" and password == r1.read():
new_win = Tk()...
elif username == "a" and password != r1.read():
sleep(5)
mainloop()
Whenever I run the program, I don't get an error message.每当我运行该程序时,我都不会收到错误消息。 However, when I type in what I have just set or set before as the password (in the txt file) or what is printed in the terminal, it sleeps the program like I got it wrong.
但是,当我输入刚刚设置或设置的密码(在 txt 文件中)或终端中打印的内容时,它会使程序休眠,就像我弄错了一样。 I've posted this before and it was too long, so it's shortened now.
之前发过,太长了,现在删了。 This is just revision for my assessment.
这只是对我的评估的修订。
For example you can do:例如你可以这样做:
File = open(‘file.txt’, ‘r’)
File_context = File.read()
File.close()
If ‘Word’ in File_context:
Print(‘FOUND!’)
Tell me if it works!告诉我它是否有效!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.