1

earlier had posted a problem about not being able to position some stuff correctly. That was solved, but now I stumbled upon another problem. I tried applying object oriented to python before and I had no problems at all. But with GUI (tkinter) seems a bit different.

Here's what I did

from tkinter import *
import tkinter.messagebox

class Validation:

    def usrVali(self, name):
        if name == " ":
            tkinter.messagebox.showinfo( "Error","Usuario incorrecto") 

        else:
             tkinter.messagebox.showinfo( "ok","dude")

vali = Validation()
form = Tk()
form.title("LogIn")
form.geometry("300x320+300+200")

usrIn = Entry(form, textvariable = None, width = 30)
usrIn.place(x = 60, y = 140)
user = usrIn.get()

passIn = Entry(form, textvariable = None, width = 30)
passIn.place(x = 60, y = 200)

usrLblVal = StringVar()
usrLblVal.set("User name")
usrLbl = Label(form, textvariable = usrLblVal  )
usrLbl.place(x = 120, y = 115)

passLblVal = StringVar()
passLblVal.set("Password")
passLbl = Label(form, textvariable = passLblVal  )
passLbl.place(x = 120, y = 175)

btn = Button(form, text = "Entrar", width = 10, command = vali.usrVali(user))
btn.place(x = 110, y = 250)

form.mainloop()

My problem is that it's calling the method before the button is actually been pressed. I want it to call the method when the button is pressed not before. Thanks.

embert
  • 7,336
  • 10
  • 49
  • 78
Jcorretjer
  • 467
  • 2
  • 6
  • 24

0 Answers0