Validity check for different data types.......................

Python-lover hemanexp at yahoo.com
Thu May 22 04:03:57 EDT 2003


hi,   I am using python and Tkinter in my application. My problem is as follows. I am using "tkSimpleDiallog" widget to display some values. I have placed 10 entry widgets in the dialog box. Among 10 entry widgets some widgets must have only string values and some others must hold intergers and others hold floats. I expect validity checks  for "KeyRelease" event for all entry eidgets. Now the problem is "do i need to have 10 validity check routines one for each entry widget? or  having 3 routines (one for string, one for int,one for float) is enough?".    My sample program is given below:*********************************************class SampleDialog(tkSimpleDialog.Dialog):
    def __init__( self, parent, title, name) :
        self.name = name[:]
        tkSimpleDialog.Dialog.__init__( self, parent, title)
        def body(self,master):
            self.SampleEntry0=Entry(master)
            self.SampleEntry0.insert(0,self.name[0])
           self.SampleEntry0.pack()
           self.SampleEntry0.bind('<KeyRelease>',self.validate_check)           self.SampleEntry1=Entry(master)
           self.SampleEntry1.insert(0,self.name[1]) 
           self.SampleEntry1.pack()
              
    def apply(self):
            self.name[0]=self.SampleEntry0.get()        
            self.name[1]=self.SampleEntry1.get()
    
    def validate_check(self,event):
       try:
             chk=self.SampleEntry0.get()
              if chk: 
                       chkval = string.atoi(chk)
                       print "No Error",chk 
                       return 1
             except ValueError:
                     tkMessageBox.showwarning("Bad input", Illegal values")
             return 0       Here i showed you only 2 entry widgets. First entry widget "SampleEntry0" holds float and second one "SampleEntry1" holds string. The routine "validate_check" checks whether the 1st entry is float or not for evry keyrelease. Suppose if i have another entry widget  say "SampleEntry2" which also holds a float, how can i change the above "validate_check" routine so that it will be used for all entry widgets that hold floats? Or do i have to repeat the same routine by only changing the line "chk = self.SampleEntry0.get() ? It is not easy to manage when number of widgets is increased.      Moreover is it possible to send the value that a entry widget has, to an event handler using "event binding"? I tried the same with  "lambda". But instead of the value i got entry widgets instance number. The code is given below. self.SampleEntry0.bind('<KeyRelease>',
            lambda
            arg1=self.SampleEntry0.get():
            self.validate_check(arg1)) #*********  Event handler     def validate_check(self,arg1):
        print arg1  So, how can i overcome above problems?  Expecting your valuable comments.Thanx.


---------------------------------
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20030522/f27a6cec/attachment.html>


More information about the Python-list mailing list