473,815 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4211
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*****@intern ode.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*****@intern ode.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
3745
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
49588
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. The question is about best practices for passing parameters to an event function. I have, say, the following HTML:
3
14964
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) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
1
1820
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_ = XtVaCreateManagedWidget("betascale", xmScaleWidgetClass, form_left, XmNtitleString, title,
5
5313
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++ Design" or similar books, but I feel there are full of clever guys here who could help me out.
0
1139
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 user can drag it to the right or left, while it does UPDATE_CONTINUOUS, but when the user lets go, I want it to go back to 1 (its center value) again. So, basically, my question is: Is it possible to make a scale widget with UPDATE_CONTINUOUS...
39
7685
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 indicate: a) That I don't know enough b) Passing arguments by ref is bad
2
1427
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 parameters? I'm mainly asking because lately I've had to do some gui programming, calling a widget function that takes like 80 defaulted arguments, with only a single one I want to alter, makes me hate life. Sorry if there's recently been a...
0
1103
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: http://wiserways.com/images/2004-02-10/intro_spotfire.jpg (see the widgets on the right of the picture) Thanks in advance!
0
9735
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9610
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10672
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10408
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10427
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9225
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7687
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5710
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.