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 1515
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 thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: lawrence |
last post by:
A very strange bug. www.monkeyclaus.org is run by a cms I'm
developing. One of types of users we allow is "justTestingTheSite", a
type of user I developed to give demo's to prospective clients. The...
|
by: Clara |
last post by:
I tried to print the value of my entry widget by passing the
result of controlvariable.get() in Tkinter to a function.
However, I kept printing empty string (eventhough I've
written something...
|
by: Michael Onfrek |
last post by:
Hi,
is copy, paste, cut of selection possible in entry widget? Docs say
selection must be copied by default, in my programm it doesn't work.
Regards, M.O.
|
by: Dave Hopper |
last post by:
Hi
I am using the following SQL to retrieve a value in a list box using a
unique ID held in the list box call cntID. The list box is used on an
order form to list appointments that have been...
|
by: Dustan |
last post by:
How do I limit what the user can enter in an Entry Widget? I know I can
set it to display '*' to hide a password, but what I want to do is
limit the contents to numeric characters. What is the...
| |
by: Dustan |
last post by:
Back in this post, I attempted to make a label look like a button:...
|
by: Kevin Walzer |
last post by:
I'm trying to construct a simple Tkinter GUI and I'm having trouble with
getting the value of an entry widget and passing it onto a callback
function. But I'm not grokking variable scope correctly....
|
by: FAQ server |
last post by:
-----------------------------------------------------------------------
FAQ Topic - How do I get the value of a form control?
-----------------------------------------------------------------------...
|
by: Elias Alhanatis |
last post by:
Hello to everybody!!
I am running Python 2.5.1 on Windows Vista and i have a problem with the
"Entry" widget of Tkinter. Take a look at this code:
from Tkinter import *
def fetch():
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |