Hi,
I need to enter only float/integer values for the "Edit" controls in my UI.I should allow to enter "alphabets".
How to check this condition?.
Thanks
PSB
11 1488
Hi,
I need to enter only float/integer values for the "Edit" controls in my UI.I should allow to enter "alphabets".
How to check this condition?.
Thanks
PSB
??? Tkinter has: Text
Entry
??? Edit ???
??? Tkinter has:Text
Entry
??? Edit ???
Sorry ,I should not allow user to enter 'Text',user is allowed to enter "float/int" values.
-PSB
Sorry ,I should not allow user to enter 'Text',user is allowed to enter "float/int" values.
-PSB
Enter into what kind of widget????
If you are using Tkinter.Entery()s, I can provide subclasses that I wrote.
I am using "Tkinter".Is possible help me with sample code?
-PSB
- from Tkinter import *
-
from dbtools import *
-
from datetime import date, time
-
from calendar import monthrange
-
-
### I tried using Tk's validatecommand callback, but it works badly.
-
### Access and choice of event bindings is much better this way.
-
### The creation of the set() method make these widgets looks like Variables.
-
-
class ValidEntry(Entry):
-
"""Validate the value of an entry widget; Use escape to go back to
-
previous value.
-
A callback routine which expects the event
-
can optionally be notified of changes to the entry. Set next to
-
a widget instance that whould get the focus next on <Return>."""
-
def __init__(self, master=None, callback=None, minvalue=None, maxvalue=None,
-
cnf={}, **kw):
-
try:
-
self.next = kw.pop('next')
-
except KeyError:
-
self.next = None
-
try:
-
self.receiver = kw.pop('receiver')
-
except KeyError:
-
self.receiver = None
-
try:
-
self.nullProc = kw.pop('nullProc')
-
except KeyError:
-
self.nullProc = None
-
Entry.__init__(self, master, cnf, **kw)
-
-
self.callback = callback
-
self.minvalue = minvalue
-
self.maxvalue = maxvalue
-
self.oldvalue = ''
-
-
self.bind('<Tab>', self.CheckValue)
-
self.bind('<Return>', self.CheckValue)
-
self.bind('<FocusOut>', self.CheckValue) # For clicks outside this widget
-
self.bind('<FocusIn>', self.ReFocus)
-
self.bind('<Escape>', self.UndoValue)
-
-
def set(self, value):
-
self.delete(0,END)
-
self.insert(0, str(value))
-
self.oldvalue = str(value)
-
-
def replace(self, value):
-
## print 'replacing %s with %s' %(repr(self.oldvalue), repr(value))
-
if self.oldvalue:
-
self.oldvalue = ''
-
self.delete(0,END)
-
self.insert(0, str(value))
-
-
def clear(self):
-
self.set('')
-
-
def convert(self, value=None):
-
"""Override this method to return an alternate format (or type)"""
-
if value is None:
-
value = self.get()
-
return value
-
-
def CheckValue(self, event=None):
-
"""If the current value is equal to oldvalue, there's nothing to
-
check. Else, validate() may change the the user-entered value,
-
so re-get() and store in oldvalue. Callbacks happen for new valid
-
values. Events are generated for old values and new valid values."""
-
if event is None:
-
event = Event()
-
event.widget = self
-
event.type = '35'
-
## print 'checking %s' %event.widget
-
value = self.get()
-
isvalid = True
-
if value != self.oldvalue:
-
if value:
-
isvalid = self.Validate(value)
-
if isvalid:
-
if type(isvalid) == bool:
-
newvalue = self.get()
-
self.oldvalue = newvalue
-
self.select_clear()
-
self.icursor(END)
-
if self.callback is not None:
-
## print 'calling back'
-
self.callback(event)
-
else: self.Invalid(isvalid[0], isvalid[1])
-
else:
-
self.Invalid()
-
else:
-
self.SendEvent(event)
-
if isvalid:
-
if event.type == '2' or event.type == '35':
-
if self.next is not None:
-
self.next.focus_set()
-
-
def Invalid(self, index1=0, index2=END):
-
self.bell()
-
self.focus_set()
-
self.select_range(index1, index2)
-
self.icursor(index1)
-
-
def Validate(self, value):
-
"""An override of this method may re-format the string
-
and then store it by calling self.replace(newvalue).
-
Call this method from inside a try block that catches the
-
ValueError exception for min/max checking after converting
-
the string to a hashable type"""
-
-
minvalue = self.minvalue
-
if minvalue is not None and value < minvalue:
-
raise ValueError
-
maxvalue = self.maxvalue
-
if maxvalue is not None and value > maxvalue:
-
raise ValueError
-
return True
-
-
def ReFocus(self, event=None):
-
self.select_range(0, END)
-
self.icursor(END)
-
-
def UndoValue(self, event=None):
-
"""Pass the <Escape> to the receiver."""
-
self.set(self.oldvalue)
-
self.ReFocus()
-
try:
-
self.receiver.event_generate("<<Entry_Escape>>")
-
except AttributeError: pass
-
-
def ReturnEvent(self):
-
"""Generate a <Return> event in this widget."""
-
event = Event()
-
event.widget = self
-
event.type = '2'
-
self.icursor(END)
-
self.CheckValue(event)
-
-
def SendEvent(self, event):
-
"""Pass the <Tab>, <Return>, <FocusOut> up the chain when
-
the value didn't change."""
-
try:
-
self.nullProc(event)
-
except TypeError: pass
-
-
def SetNextWidget(self, nextWidget):
-
self.next = nextWidget
-
-
def GetNextWidget(self):
-
return self.next
-
-
def SetRecWidget(self, receiver):
-
self.receiver = receiver
-
-
def SetNullProc(self, nullProc):
-
self.nullProc = nullProc
-
-
def SetCallback(self, callback):
-
self.callback = callback
-
-
def Close(self):
-
self.ReturnEvent()
-
# Date and Time Entries remove due to post-size limit #
-
-
class IntegerEntry(ValidEntry):
-
def Validate(self, value):
-
try:
-
a = int(value)
-
ValidEntry.Validate(self, a)
-
return True
-
except ValueError:
-
return False
-
-
def convert(self, value=None):
-
if value is None:
-
value = self.get()
-
try:
-
value = int(value)
-
except ValueError:
-
pass
-
return value
-
-
class FloatEntry(ValidEntry):
-
def Validate(self, value):
-
try:
-
a = float(value)
-
ValidEntry.Validate(self, a)
-
return True
-
except ValueError:
-
return False
-
-
def convert(self, value=None):
-
if value is None:
-
value = self.get()
-
try:
-
value = float(value)
-
except ValueError:
-
pass
-
return value
-
-
class HexEntry(ValidEntry):
-
def Validate(self, value):
-
try:
-
a = int(value, 16)
-
ValidEntry.Validate(self, a)
-
self.replace(value.upper())
-
return True
-
except ValueError:
-
return False
-
-
class DollarEntry(FloatEntry):
-
def __init__(self, master=None, callback=None, minvalue=None, maxvalue=None,
-
cnf={}, **kw):
-
ValidEntry.__init__(self, master, callback, minvalue, maxvalue, cnf, **kw)
-
self.config(justify=RIGHT)
-
-
def Validate(self, value):
-
try: # Allow up to 5 places to the right of dp
-
if value[0] == '$':
-
value = value[1:]
-
a = float(value)
-
ValidEntry.Validate(self, a)
-
a = '$%.5f' %a
-
self.replace(a[:-3]) # but only keep 2
-
return True
-
except ValueError:
-
return False
-
-
def get(self):
-
value = Entry.get(self)
-
if value:
-
if value[0] == '$':
-
value = value[1:]
-
return value
-
-
class StringEntry(ValidEntry):
-
"""Disable minvalue and maxvalue, allow all text."""
-
def Validate(self, value):
-
return True
-
-
class StateEntry(ValidEntry):
-
def Validate(self, value):
-
if len(value) > 2 or not value.isalpha():
-
return False
-
self.replace(value.upper())
-
return True
-
-
class NameEntry(ValidEntry):
-
def Validate(self, value):
-
l = value.split()
-
value = ' '.join(value.capitalize() for value in l)
-
self.replace(value)
-
return True
-
-
class PhoneEntry(ValidEntry):
-
def Validate(self, value):
-
for char in set(' -()').intersection(value):
-
l = value.split(char)
-
value = ''.join(l)
-
i = len(value)
-
if i >= 7:
-
if i == 7 and int(value[0]) > 1:
-
self.replace('%s-%s' %(value[:3], value[3:]))
-
return True
-
if i == 8 and value[0] == '1':
-
self.replace('1-%s-%s' %(value[1:4], value[4:]))
-
return True
-
if i == 10 and int(value[0]) > 1:
-
self.replace('(%s) %s-%s' %(value[:3], value[3:6], value[6:]))
-
return True
-
if i == 11 and value[0] == '1':
-
self.replace('1-(%s) %s-%s' %(value[1:4], value[4:7], value[7:]))
-
return True
-
return False
-
-
-
-
if __name__ == '__main__':
-
root = Tk(className='widget test window')
-
top = Frame()
-
top.pack()
-
-
def cb(event):
-
print 'Callback called by event type %s' %(event.type)
-
-
de = DateEntry(top, width=11, callback=cb)
-
pe = PhoneEntry(top, width=15, callback=cb)
-
ne = TimeEntry(top, callback=cb)
-
-
de.next = pe
-
pe.next = ne
-
ne.next = de
-
-
de.pack()
-
pe.pack()
-
ne.pack()
-
de.setdate('')
-
root.mainloop()
I dont have dbtools modules
"from dbtools import *" - Sample
-
IDLE 1.1.4
-
>>> ================================ RESTART ================================
-
>>>
-
-
Traceback (most recent call last):
-
File "C:\Validtaion.py", line 2, in -toplevel-
-
from dbtools import *
-
ImportError: No module named dbtools
-
>>>
-
I dont have dbtools modules
"from dbtools import *" - Sample
-
IDLE 1.1.4
-
>>> ================================ RESTART ================================
-
>>>
-
-
Traceback (most recent call last):
-
File "C:\Validtaion.py", line 2, in -toplevel-
-
from dbtools import *
-
ImportError: No module named dbtools
-
>>>
-
The module that I posted is very old. Feel free to simply remove the parts that you need and chuck the rest.
I tried commenting the "from dbtools import *" and related methods.But I am not able to see any UI controls.
-PSB
I tried commenting the "from dbtools import *" and related methods.But I am not able to see any UI controls.
-PSB
I'm still not clear on whether Tkinter.Entery is what you are looking for...
Validation for the Data enetered in UI controls.
I am looking for the data enetr in the "Edit Box"Controls.
Suppose user wants to enter the ineteger values only in the Edit Box,So the code has to check for only integer values entry.If by mistake user enters "alphabets/special characters",the edit box should not allow to take.Otherwise the application crashes or we have to throw error
-PSB
Validation for the Data enetered in UI controls.
I am looking for the data enetr in the "Edit Box"Controls.
Suppose user wants to enter the ineteger values only in the Edit Box,So the code has to check for only integer values entry.If by mistake user enters "alphabets/special characters",the edit box should not allow to take.Otherwise the application crashes or we have to throw error
-PSB
The thing is this:
I've never heard of an "Edit Box" Control.
If you can - from Tkinter import EditBox
then you need to show what you are doing.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Kevin Myers |
last post by:
Hello,
Please forgive my reposting of this note with hopefully a more relevant
subject line.
On an Access 2000 form under Windows 2000 I would like to use a Kodak Image
Edit Control to...
|
by: doronb |
last post by:
hello
my question is :
i define dynamic columns to datagrid , 4 columns are databound and 1
columne is "edit template column" and only this col editable ,
i define function for update when...
|
by: Glenn M |
last post by:
I have a shared XML file on a server .
i also have one xslt file that performs a simple transform on in to
view the data.
now i want to have another page that lets users modify the shared xml...
|
by: Leo |
last post by:
I have a datagrid with the first column as a Edit,Update,Cancel button
column. The other 5 columns are template columns. When I click the Edit
button in IE6 the row correctly displays the...
|
by: mwhalen |
last post by:
Hi All,
I've dynmaically created a textbox, but I can't edit it. When I click on
it, the cursor flashes for a second, but then goes away and I can't enter any
text or do anything with the value...
|
by: Luqman |
last post by:
How can I put GridView and DetailView control to Edit Mode with one click of
button ?
I don't want to show built-in Edit Buttons of above controls.
Best Regards,
Luqman
|
by: Vish |
last post by:
Hi,
I amplanning on having a rea-only and edit states for my form. But it do not
want my form and its controls to look different or disabled. I am planning on
having a edit button that brings...
|
by: rn5a |
last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB
table. Users can modify the records using this DataGrid for which I am
using EditCommandColumn in the DataGrid. This is the...
|
by: =?Utf-8?B?bWlrZWc=?= |
last post by:
Hi,
I am building a small Help Desk application for my company and need to be
able to edit "open" help desk issues. I use a simple datagrid to display
each issue (6 per page) , with an Edit...
|
by: Arielle |
last post by:
Background: I have a generated datalist to display information and I need to add the capability to have a button (Edit button) so that users can change the information. I'm sure once I figure it...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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: 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...
| |