Hi
I need a spinbox which when created can read a variable (which is an integer) from another location and use that variable for the starting value. i also need to only allow integers be input into the text field by keyboard (and only has high as 999). lastly, whenever the spinbox value is changed (either by keyboard input or by clicking on the arrows) i need to be able to verify that it is an integer and then save its value into another location.
i have tried to do these things but without success. currently i have this (it has been cut out of my main program: - resistanceEntry = Spinbox(resistorFrame, from_=1, to=999, width=10, wrap=True, validate=ALL, validatecommand=validate)
-
-
def validate():
-
print "VALIDATE"
i noticed that even with validate set to ALL it only runs the command validate once and that is when the spinbox is first created.
any help would be greatly appreciated, but please try and keep it simple i am still very new to this
thanks
12 8597
Hi
I need a spinbox which when created can read a variable (which is an integer) from another location and use that variable for the starting value. i also need to only allow integers be input into the text field by keyboard (and only has high as 999). lastly, whenever the spinbox value is changed (either by keyboard input or by clicking on the arrows) i need to be able to verify that it is an integer and then save its value into another location.
i have tried to do these things but without success. currently i have this (it has been cut out of my main program: - resistanceEntry = Spinbox(resistorFrame, from_=1, to=999, width=10, wrap=True, validate=ALL, validatecommand=validate)
-
-
def validate():
-
print "VALIDATE"
i noticed that even with validate set to ALL it only runs the command validate once and that is when the spinbox is first created.
any help would be greatly appreciated, but please try and keep it simple i am still very new to this
thanks
Electronics huh?
I'm guessing that you need to associate a Variable class object that gets changes. I'll have a look tonight. Got to go at the moment.
Hi
I need a spinbox which when created can read a variable (which is an integer) from another location and use that variable for the starting value. i also need to only allow integers be input into the text field by keyboard (and only has high as 999). lastly, whenever the spinbox value is changed (either by keyboard input or by clicking on the arrows) i need to be able to verify that it is an integer and then save its value into another location.
i have tried to do these things but without success. currently i have this (it has been cut out of my main program: - resistanceEntry = Spinbox(resistorFrame, from_=1, to=999, width=10, wrap=True, validate=ALL, validatecommand=validate)
-
-
def validate():
-
print "VALIDATE"
i noticed that even with validate set to ALL it only runs the command validate once and that is when the spinbox is first created.
any help would be greatly appreciated, but please try and keep it simple i am still very new to this
thanks
Nice job on the CODE tags. Thanks. I like you naming style, too.
Validators must return True or False: - resistanceEntry = Spinbox(resistorFrame, from_=1, to=999, width=10, wrap=True, validate=ALL, validatecommand=validate)
-
-
def validate():
-
print "VALIDATE"
-
return True
Perhaps returning None is causing the problem.
thank you so much :) when i return true then it validates every time, now all i need is get the spinbox value to start at a specific value, any ideas?
EDIT: also how would i write the validate function i had the idea of this (below) but it seems very inefficient there must be a better way -
-
def validate(input)
-
for i in range (1000):
-
if i == input:
-
return True
-
(...etc...)
-
bvdet 2,851
Expert Mod 2GB
EDIT: also how would i write the validate function i had the idea of this (below) but it seems very inefficient there must be a better way -
-
def validate(input)
-
for i in range (1000):
-
if i == input:
-
return True
-
(...etc...)
-
Something like this: - >>> def validate(v):
-
... if isinstance(v, int) and v > 0 and v < 1000:
-
... return True
-
... else:
-
... return False
-
...
-
>>> validate(6)
-
True
-
>>> validate(0)
-
False
-
>>> validate(999)
-
True
-
>>> validate(1000)
-
False
-
>>> if validate(v):
-
... print 'Do some stuff'
-
...
-
Do some stuff
-
>>>
thank you so much :) when i return true then it validates every time, now all i need is get the spinbox value to start at a specific value, any ideas?
In the Frame's __init__(), keep a reference: - self.resistanceEntry = Spinbox(resistorFrame, from_=1, to=999, width=10, wrap=True, validate=ALL, validatecommand=validate)
Then, any time you want to, the a Frame method can - resistanceEntry.set(value)
or you can might be able to - STARTVALUE = 100 # or whatever
-
resistanceEntry = Spinbox(resistorFrame, from_=1, to=999,
-
value=STARTVALUE, width=10, wrap=True,
-
validate=ALL, validatecommand=validate)
Of, course, you'll have to experiment because I have not tested this.
Do you know where to find/have the on-line Tkinter reference???
In the Frame's __init__(), keep a reference: - self.resistanceEntry = Spinbox(resistorFrame, from_=1, to=999, width=10, wrap=True, validate=ALL, validatecommand=validate)
Then, any time you want to, the a Frame method can - resistanceEntry.set(value)
or you can might be able to - STARTVALUE = 100 # or whatever
-
resistanceEntry = Spinbox(resistorFrame, from_=1, to=999,
-
value=STARTVALUE, width=10, wrap=True,
-
validate=ALL, validatecommand=validate)
Of, course, you'll have to experiment because I have not tested this.
Do you know where to find/have the on-line Tkinter reference???
Actually, I think that the proper way to do this is with and IntVar. There is a discussion here.
The Tkinter (old and incomplete) reference is here.
We'll make a Pythoneer out of you, yet!
Something like this: - >>> def validate(v):
-
... if isinstance(v, int) and v > 0 and v < 1000:
-
... return True
-
... else:
-
... return False
-
...
-
>>> validate(6)
-
True
-
>>> validate(0)
-
False
-
>>> validate(999)
-
True
-
>>> validate(1000)
-
False
-
>>> if validate(v):
-
... print 'Do some stuff'
-
...
-
Do some stuff
-
>>>
this is perfect except how would you write isinstance? (its not a built in is it?)
i have taken in all of the other things people have written and just have one more question: i noticed that if i use the validatecommand function as used below then the validation is always one step behind. ie if the spinbox contains 5 and i change it to 6 it will verify the old value of 5 and then change the spinbox value of 6, thus it is always one step behind. is there any way to fix this or is there a way around it? -
resistorProperties.resistanceEntry = Spinbox(resistorProperties.resistorFrame, from_=1, to=999, width=10, wrap=True, validate="all", validatecommand=validate) #use get() to find entry
-
resistorProperties.resistanceEntry.grid(column=1, row=1, sticky=N+E)
-
-
def validate():
-
print "VALIDATE"
-
-
if resistorProperties.resistanceEntry == None:
-
return True
-
else:
-
toValidate = resistorProperties.resistanceEntry.get()
-
-
print toValidate
-
return True
-
this is perfect except how would you write isinstance? (its not a built in is it?)
worked that part out, only the second part applies :)
worked that part out, only the second part applies :)
I fixed the event-sequence problem using an IntVar and trace().
I will ask you to consider designing you resistor model as a subclass of Frame, as follows: -
-
class ResistorModel(Frame):
-
"""A subclass of Tkinter.Frame for modeling a resistor using IntVar."""
-
def __init__(self, root, powerRating, *args, **kwargs):
-
Frame.__init__(self, root, *args, **kwargs)
-
self.powerRating = powerRating
-
self.Ohms = IntVar()
-
self.Ohms.trace('w', self.validateOhms)
-
-
## label = Label()
-
-
self.resistanceEntry = Spinbox(self, from_=1, to=999, width=10, wrap=True,
-
validate="all", textvariable=self.Ohms) #use get() to find entry
-
## self.resistanceEntry.config(validatecommand=self.validateOhms)
-
self.resistanceEntry.grid(column=1, row=1, sticky=N+E)
-
-
def validateOhms(self, *args):
-
print "VALIDATE OHMS"
-
toValidate = self.Ohms.get()
-
-
print toValidate, type(toValidate)
-
return True
-
-
-
if __name__ == "__main__":
-
root = Tk()
-
-
frame = ResistorModel(root, 10)
-
frame.pack()
-
I fixed the event-sequence problem using an IntVar and trace().
I will ask you to consider designing you resistor model as a subclass of Frame, as follows: -
-
class ResistorModel(Frame):
-
"""A subclass of Tkinter.Frame for modeling a resistor using IntVar."""
-
def __init__(self, root, powerRating, *args, **kwargs):
-
Frame.__init__(self, root, *args, **kwargs)
-
self.powerRating = powerRating
-
self.Ohms = IntVar()
-
self.Ohms.trace('w', self.validateOhms)
-
-
## label = Label()
-
-
self.resistanceEntry = Spinbox(self, from_=1, to=999, width=10, wrap=True,
-
validate="all", textvariable=self.Ohms) #use get() to find entry
-
## self.resistanceEntry.config(validatecommand=self.validateOhms)
-
self.resistanceEntry.grid(column=1, row=1, sticky=N+E)
-
-
def validateOhms(self, *args):
-
print "VALIDATE OHMS"
-
toValidate = self.Ohms.get()
-
-
print toValidate, type(toValidate)
-
return True
-
-
-
if __name__ == "__main__":
-
root = Tk()
-
-
frame = ResistorModel(root, 10)
-
frame.pack()
-
wow it works :) thank you so much your code is fantastic and with minimal modification this can easily be placed directly into my program.
i apologise for the late reply but i have been swamped over the last few weeks and have not had any time to work on my program
:)
wow it works :) thank you so much your code is fantastic and with minimal modification this can easily be placed directly into my program.
i apologise for the late reply but i have been swamped over the last few weeks and have not had any time to work on my program
:)
I was just wondering about you today. Thank you for the update.
Keep posting, (like some working code, maybe)
Barton
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Josh |
last post by:
Caution, newbie approaching...
I'm trying to come up with a very simple Tkinter test application that
consists of a window with a drop-down menu bar at the top and a grid
of colored rectangles...
|
by: srijit |
last post by:
Hello,
Any idea - why the following code crashes on my Win 98 machine with
Python 2.3? Everytime I run this code, I have to reboot my machine.
I also have Win32all-157 installed.
from Tkinter...
|
by: Tony Eva |
last post by:
The spinbox widget in Tk 8.4 has an option to allow a command
to be specified that is invoked when either the up or down buttons
of the spinbox are pressed, as in:
...
self.sb =...
|
by: Askari |
last post by:
Hi,
I search on google a example for Spinbox (with Tkinter module). Can't
find! If someone have a basic example for with a Spinbox, send me him!
Because? I don't know how use this widget! :-( ...
|
by: syed_saqib_ali |
last post by:
Below is a simple code snippet showing a Tkinter Window bearing a
canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine.
When you shrink/resize the window the scrollbars adjust...
|
by: Michael Yanowitz |
last post by:
Hello:
Below I have included a stripped down version of the GUI I am working on.
It contains 2 dialog boxes - one main and one settings. It has the following
problems, probably all related, that...
|
by: aft3rgl0w |
last post by:
hello everyone, i am trying to create an activex clock control, which can display the current time or be used to set a time in a control. i am using Visual Basic 2005, with 3 numericupdown...
|
by: karthikbalaguru |
last post by:
Hi,
One of my python program needs tkinter to be installed to run
successfully.
I am using Redhat 9.0 and hence tried installing by copying the
tkinter-2.2.2-36.i386.rpm
alone from the CD 3 to...
|
by: joshdw4 |
last post by:
I hate to do this, but I've thoroughly exhausted google search. Yes,
it's that pesky root window and I have tried withdraw to no avail. I'm
assuming this is because of the methods I'm using. I...
|
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: 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: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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: 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,...
| |