If 语句取决于 .txt 文件的内容 - Python 3.9
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()
每当我 运行 程序时,我都没有收到错误消息。但是,当我输入我刚刚设置或之前设置的密码(在 txt 文件中)或终端中打印的内容时,它会使程序休眠,就像我弄错了一样。之前发过,太长了,现在删了。这只是我评估的修正。
例如你可以这样做:
File = open(‘file.txt’, ‘r’)
File_context = File.read()
File.close()
If ‘Word’ in File_context:
Print(‘FOUND!’)
告诉我它是否有效!
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()
每当我 运行 程序时,我都没有收到错误消息。但是,当我输入我刚刚设置或之前设置的密码(在 txt 文件中)或终端中打印的内容时,它会使程序休眠,就像我弄错了一样。之前发过,太长了,现在删了。这只是我评估的修正。
例如你可以这样做:
File = open(‘file.txt’, ‘r’)
File_context = File.read()
File.close()
If ‘Word’ in File_context:
Print(‘FOUND!’)
告诉我它是否有效!