473,218 Members | 1,322 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,218 software developers and data experts.

passing arguments from scale widget to function

Some time ago I wrote a little program in Tcl/Tk that took the values
from 3 sliders and performed a calculation using these values. The
calculation was of course automatically repeated each time a slider was
moved.

It is proving most difficult in Python. How do I pass the .get() values
to my calculating function? Do I use the command option for each
slider? e.g command = Calc(a.get()). Obviously not cos it doesn't work.

I am not a real programmer and do not wish to get involved in classes
and objects....
Aug 21 '05 #1
7 4166
On Sun, 21 Aug 2005 08:09:55 +0100, m7b52000 <oh*************@noSPAM.com>
wrote:
It is proving most difficult in Python. How do I pass the .get() values
to my calculating function? Do I use the command option for each slider?
e.g command = Calc(a.get()). Obviously not cos it doesn't work.
It should work if you wrap it as a lambda function. As it is, you're
assigning the
result of the Calc() function to the 'command' argument/parameter of the
slider widget. What you actually want is to assign just the function:

command = lambda : Calc(a.get())
I am not a real programmer and do not wish to get involved in classes
and objects....


If you're using Tcl/Tk you're already using them ... what do you think
your Slider widget is? :-)

Hope this helps!

regards
Matt
--

| Matt Hammond
| R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK.
Aug 22 '05 #2
Matt Hammond wrote:
On Sun, 21 Aug 2005 08:09:55 +0100, m7b52000
<oh*************@noSPAM.com> wrote:
It is proving most difficult in Python. How do I pass the .get()
values to my calculating function? Do I use the command option for
each slider? e.g command = Calc(a.get()). Obviously not cos it
doesn't work.

It should work if you wrap it as a lambda function. As it is, you're
assigning the
result of the Calc() function to the 'command' argument/parameter of
the slider widget. What you actually want is to assign just the function:

command = lambda : Calc(a.get())
I am not a real programmer and do not wish to get involved in classes
and objects....

If you're using Tcl/Tk you're already using them ... what do you think
your Slider widget is? :-)

Hope this helps!

regards
Matt

Thanks,

I get the following message when I use lambda as above:

TypeError: <lambda>() takes no arguments (1 given)

any other thoughts :)

Tony
Aug 22 '05 #3
On Mon, 22 Aug 2005 12:16:01 +0100, m7b52000 <tp*****@internode.on.net>
wrote:
command = lambda : Calc(a.get())
I get the following message when I use lambda as above:

TypeError: <lambda>() takes no arguments (1 given)


Oops, forgot! The Scale widget outputs a single argument - the value of
the slider. You therefore could write:

command = lambda value : Calc(value)

or even simpler:

command = Calc

In the latter case, you're supplying your "calc" function as the function
to be called. Calc takes a single argument - the value of the slider, so
it fulfills the task. Note that we're passing "Calc" (the function
itself), not "Calc(...)" (the result of calling the function)

regards
Matt

--

| Matt Hammond
| R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK.
Aug 22 '05 #4
Matt Hammond wrote:
On Mon, 22 Aug 2005 12:16:01 +0100, m7b52000 <tp*****@internode.on.net>
wrote:
command = lambda : Calc(a.get())


I get the following message when I use lambda as above:

TypeError: <lambda>() takes no arguments (1 given)

Oops, forgot! The Scale widget outputs a single argument - the value of
the slider. You therefore could write:

command = lambda value : Calc(value)

or even simpler:

command = Calc

In the latter case, you're supplying your "calc" function as the
function to be called. Calc takes a single argument - the value of the
slider, so it fulfills the task. Note that we're passing "Calc" (the
function itself), not "Calc(...)" (the result of calling the function)

regards
Matt

Ahhhh. Partial success with : command = Calc. A slider will now pass its
argument to a function without problem. My Calc function however is
expecting 3 arguments - 1 from each slider i.e moving any of the 3
sliders should cause a recalculation. I am now getting the following error:
TypeError: Calc() takes exactly 3 arguments (1 given)

p.s your help is much appreciated....
Aug 22 '05 #5
> Ahhhh. Partial success with : command = Calc. A slider will now pass its
argument to a function without problem. My Calc function however is
expecting 3 arguments - 1 from each slider i.e moving any of the 3
sliders should cause a recalculation. I am now getting the following
error:
TypeError: Calc() takes exactly 3 arguments (1 given)


I'm sure you can figure this out now! Either:
use lambda functions, as described, to call Calc with the correct
arguments
or:
write three functions (one for each slider) that call Calc with all 3
arguments it requires

regards

Matt
--

| Matt Hammond
| R&D Engineer, BBC Research and Development, Tadworth, Surrey, UK.
Aug 22 '05 #6
Matt Hammond wrote:
Ahhhh. Partial success with : command = Calc. A slider will now pass
its argument to a function without problem. My Calc function however
is expecting 3 arguments - 1 from each slider i.e moving any of the
3 sliders should cause a recalculation. I am now getting the
following error:
TypeError: Calc() takes exactly 3 arguments (1 given)

I'm sure you can figure this out now! Either:
use lambda functions, as described, to call Calc with the correct
arguments
or:
write three functions (one for each slider) that call Calc with all 3
arguments it requires

regards

Matt

Have already started on the 2nd aproach. I might become a programmer
yet...............
Aug 22 '05 #7
Problem solved. use 'command = Calc' to call my Calc function but ignore
the argument passed to it. Create a list with the following elements -
a.get(), b.get() and c.get(). Every time a scale slider is moved, Calc
will retrieve the current scale values and I can do with them whatever I
want...

Now to work out how to write the answer to a text box or similar.......

Thanks for your help, Matt

Tony
Aug 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Fouhy | last post by:
So I've got a horizontal scale widget in my GUI. When I click the mouse in the area to the right of the GUI, the scale advances by 1. 13 +-------------------------+ |<| X |>|...
7
by: Pavils Jurjans | last post by:
Hallo, I have been programming for restricted environments where Internet Explorer is a standard, so I haven't stumbled upon this problem until now, when I need to write a DOM-compatible code. ...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
1
by: Daniel Tscharnuter | last post by:
Hello! First of all, I am new to C++. The problem with the scale widget is that I get a segmentation fault when I want to create it with more than zero decimal numbers. beta_scale_ =...
5
by: Pelle Beckman | last post by:
Hi, I've done some progress in writing a rather simple singleton template. However, I need a smart way to pass constructor arguments via the template. I've been suggested reading "Modern C++...
0
by: ch424 | last post by:
Hi I'm trying to make a zooming in/out slider, but I want to make it re-center when I let go of the mouse button on it -- i.e. it starts with a value of 1 (in the center of the slider), then the...
39
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
2
by: xideum | last post by:
Hi. Question: In a function that takes multiple arguments, each with a default value setis there anyway to either alter the order of the parameters you pass to it or skip the passing of certain...
0
by: WLigtenberg | last post by:
Hi, I'm looking for a Scale like Tkinter widget that has two sliders, so that the user can select both the upper and lower bound of some dataset. Much like the widgets used in spotfire:...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.