簡體   English   中英

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!’)

告訴我它是否有效!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM