Python Tkinter Entry not working

When I click on button on mainloop (should execute function password() witch than creates tkinter with entry) when I type something into the entry and press Enter, it should go to function on_change(), but the thing is that when I click on the button I can see that immediately after the click message "Python function passed" is in console which means that the function is called right after I press the button to create this new tkinter window, not when I press enter, and also you can see that line pass = self.Entry1.get() is commented, that is because it is giving me a SyntaxError: invalid syntax, but I don't see why is that happening, can anyone explain to me what is wrong with the code?

def tk_start_gui():
    global root
    root = Tk()
    top = DProgram(root)
    root.mainloop()

def password(type):
    global passroot
    passroot = Tk()
    top = PassProgram(passroot, type)

class PassProgram:
    def __init__(self, top=None, passtype=None):
        bgcolor = '#d9d9d9'  # X11 color: 'gray85'

        top.geometry("300x100+480+222")
        top.title("Enter Password")
        top.configure(background=bgcolor)

        self.Frame1 = LabelFrame(top)
        self.Frame1.place(relx=0.02, rely=0.02, relheight=0.94, relwidth=0.96)
        self.Frame1.configure(text='Enter Password')
        self.Frame1.configure(relief=GROOVE)
        self.Frame1.configure(borderwidth="2")
        self.Frame1.configure(relief=GROOVE)
        self.Frame1.configure(background="#d9d9d9")
        self.Frame1.configure(width=575)

        self.Label1 = Label(self.Frame1)
        self.Label1.place(relx=0.01, rely=0.01)
        self.Label1.configure(background="#d9d9d9")
        self.Label1.configure(disabledforeground="#a3a3a3")
        self.Label1.configure(foreground="#000000")
        self.Label1.configure(text='''Enter password to access {} settings'''.format(passtype))

        self.Entry1 = Entry(self.Frame1)
        self.Entry1.place(relx=0.05, rely=0.1)
        self.Entry1.configure(width=46)
        self.Entry1.configure(show="*")
        self.Entry1.bind("<Return>", self.on_change())
        self.Entry1.pack(side=LEFT)

    def on_change(self, *args):
        # pass = self.Entry1.get()
        print("function passed")
        self.Entry1.delete(0, 'end')
tk_start_gui()

python python-3.x class tkinter tkinter-entry

1reply Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Hi Azhar, sorry for the delayed response. If you're still having this issue, could you possibly write into our in product chat (by clicking on the blue question mark and then contact us) so that we may assist you further?

    Reply Like
Like Follow
  • 4 wk agoLast active
  • 1Replies
  • 191Views
  • 2 Following