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() 4 1302
Clara wrote: 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
Clara wrote:
<SNIP> self.loginButton = Button(self, text='Login', command = VerifyProcessor(self.x.get(), self.y.get()) )
<SNIP> 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.
Yes that solves my problem all right...THanks a bunch to both of you
Yes that solves my problem all right...THanks a bunch to both of you This discussion thread is closed Replies have been disabled for this discussion. Similar topics
2 posts
views
Thread by lawrence |
last post: by
|
reply
views
Thread by Clara |
last post: by
|
4 posts
views
Thread by Michael Onfrek |
last post: by
|
6 posts
views
Thread by Dave Hopper |
last post: by
|
2 posts
views
Thread by Dustan |
last post: by
|
4 posts
views
Thread by Dustan |
last post: by
|
2 posts
views
Thread by Kevin Walzer |
last post: by
|
17 posts
views
Thread by FAQ server |
last post: by
| | | | | | | | | | | |