-2

I am trying to make an entry box that moves to another window if what is typed in is equal to the contents of what is in a text file. this is what I have so far:

import tkinter


def Window1():
    window2 = tkinter.Tk()
    window2.title("admin")
    entry_user = tkinter.Entry(window2)
    entry_pwd = tkinter.Entry(window2)
    button = tkinter.Button(window2, text = "enter", command = Enter)

    entry_user.pack()
    entry_pwd.pack()
    button.pack()

def Enter():
    entry_user_1 = entry_user.get()
    entry_pwd_1 = entry_pwd.get()
    f = open("adminusername.txt", "w+")
    g = open("adminpassword.txt", "w+")
    if entry_user_1 in f.read() and entry_pwd_1 in g.read():
        window5 = tkinter.Tk()
        window5.title("add account")

window = tkinter.Tk()
window.title("login")

button = tkinter.Button(window, text = "admin", command = Window1)
button.pack()

the files I am using are adminusername.txt and adminpassword.txt thank you to anyone who can help with this problem

Oscar Biggins
  • 13
  • 1
  • 8
  • Which entry box do you want to move, and in which window ? – Phoenixo Feb 11 '20 at 17:10
  • sorry I want to check if the entry_user and the entry_pwd in window2 are equal to the contents of the adminuser.txt and adminpassword.txt files – Oscar Biggins Feb 11 '20 at 17:13
  • 1
    Read [Why are multiple instances of Tk discouraged?](https://stackoverflow.com/questions/48045401/why-are-multiple-instances-of-tk-discouraged) and [Tkinter understanding mainloop](https://stackoverflow.com/questions/29158220/tkinter-understanding-mainloop) – stovfl Feb 11 '20 at 17:26
  • 1
    Your title doesn't seem to match the body of the question. Are you literally asking how to _move_ a widget between windows? – Bryan Oakley Feb 11 '20 at 17:26
  • Generally speaking, you only call `tkinter.Tk()` _once_ and then use [`tkinter.Toplevel()`](https://web.archive.org/web/20190429194251id_/http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/toplevel.html) to create independent top-level windows if you need them. Instead of having multiple windows, consider having multiple `Frame`s — see [Switch between two frames in tkinter](https://stackoverflow.com/questions/7546050/switch-between-two-frames-in-tkinter). – martineau Feb 11 '20 at 17:28
  • Why have you accepted @phoenixo's answer which doesn't seem to have anything to do with your question? – martineau Feb 11 '20 at 17:29

1 Answers1

1

You are currently writing in your text files with open("adminpassword.txt", "w+"). You should change the w option to r in order to read the content :

f = open("adminusername.txt", "r")
Phoenixo
  • 2,071
  • 1
  • 6
  • 13