The value of the entry widget doesn't get updated

C

Clara

Hi, can somebody help me,..I have an assignment due next week but now
I'm stuck with this problem....
I tried to get values from entry widget using the
widgetcontrolvariable.get(),..but it seems that it won't work....
I can't print the value I input in the entry widget...However when I
first set the value to something I can get the value just fine...
This is my code
Help please...

msg='*~*Please Login to use the system*~*'
class LoginMenu(Frame):

def createWidgets(self, msg):
import tkFont
self.x = StringVar()
self.y = StringVar()
self.x.set("Type here")
self.messageLabel= Label(self, text=msg, pady=15,
font=tkFont.Font(weight='bold' ,size=10))
self.messageLabel.grid(row=0, columnspan=6)
self.nameLabel= Label(self, text='UserName :', padx=12,
justify=LEFT)
self.nameLabel.grid(row=1, column=0, ipadx=9, ipady=5)
self.nameEntry= Entry(self,justify=LEFT, textvariable=self.x)
self.nameEntry.grid(row=1, column=3, columnspan=2)
self.nameEntry.update_idletasks()
self.passLabel= Label(self, text='Password :', padx=12,
justify=LEFT)
self.passLabel.grid(row=2, column=0,ipadx=9, ipady=5)
self.passEntry= Entry(self,justify=LEFT, show='*',
textvariable=self.y)
self.passEntry.grid(row=2, column=3, columnspan=2)
self.passEntry.update_idletasks()
self.loginButton = Button(self, text='Login', command =
VerifyProcessor(self.x.get(), self.y.get()) )
self.loginButton.grid(row=4, column=3, ipadx=15, ipady=3, pady=20)
self.quitButton = Button(self, text='Exit', command = self.quit)
self.quitButton.grid(row=4, column=4, ipadx=20, ipady=3, pady=20,
padx=10)

def __init__(self, msg, master=None):
Frame.__init__(self, master)
self.grid(column=4, row=4)
self.createWidgets(msg)

class VerifyProcessor:

def __init__(self, thename, thepass):
self.username = thename
self.password = thepass

def __call__(self):
print self.username
print self.password


app = LoginMenu(msg)
app.master.title("Login Menu")
app.master.maxsize(280,200)
app.mainloop()
 
M

Martin Franklin

Clara said:
Hi, can somebody help me,..I have an assignment due next week but now
I'm stuck with this problem....
I tried to get values from entry widget using the
widgetcontrolvariable.get(),..but it seems that it won't work....
I can't print the value I input in the entry widget...However when I
first set the value to something I can get the value just fine...
This is my code
Help please...

msg='*~*Please Login to use the system*~*'
class LoginMenu(Frame):

def createWidgets(self, msg):
import tkFont
self.x = StringVar()
self.y = StringVar()
self.x.set("Type here")
self.messageLabel= Label(self, text=msg, pady=15,
font=tkFont.Font(weight='bold' ,size=10))
self.messageLabel.grid(row=0, columnspan=6)
self.nameLabel= Label(self, text='UserName :', padx=12,
justify=LEFT)
self.nameLabel.grid(row=1, column=0, ipadx=9, ipady=5)
self.nameEntry= Entry(self,justify=LEFT, textvariable=self.x)
self.nameEntry.grid(row=1, column=3, columnspan=2)
self.nameEntry.update_idletasks()
self.passLabel= Label(self, text='Password :', padx=12,
justify=LEFT)
self.passLabel.grid(row=2, column=0,ipadx=9, ipady=5)
self.passEntry= Entry(self,justify=LEFT, show='*',
textvariable=self.y)
self.passEntry.grid(row=2, column=3, columnspan=2)
self.passEntry.update_idletasks()
self.loginButton = Button(self, text='Login', command =
VerifyProcessor(self.x.get(), self.y.get()) )


Here is the problem, the values of the two entries have been got'on
before the button is pressed and the command is called.

I would replace the above with:-

VerifyProcessor(self.x, self.y)) )

and see below for the changes to the command callback class

self.loginButton.grid(row=4, column=3, ipadx=15, ipady=3, pady=20)
self.quitButton = Button(self, text='Exit', command = self.quit)
self.quitButton.grid(row=4, column=4, ipadx=20, ipady=3, pady=20,
padx=10)

def __init__(self, msg, master=None):
Frame.__init__(self, master)
self.grid(column=4, row=4)
self.createWidgets(msg)

class VerifyProcessor:

def __init__(self, thename, thepass):
self.username = thename
self.password = thepass

def __call__(self):
print self.username
print self.password

print self.username.get()
print self.password.get()


app = LoginMenu(msg)
app.master.title("Login Menu")
app.master.maxsize(280,200)
app.mainloop()


HTH
Martin
 
T

tiissa

Clara wrote:
self.loginButton = Button(self, text='Login', command =
VerifyProcessor(self.x.get(), self.y.get()) )
class VerifyProcessor:

def __init__(self, thename, thepass):
self.username = thename
self.password = thepass

def __call__(self):
print self.username
print self.password

Your VerifyProcessor object is constructed just before your loginButton,
not when you click.
Therefore you may want to pass the x and y StringVars to its __init__
function instead of their value at contruction. Therefore your __call__
method can .get() their values each time the button is clicked.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top