Re: [Tutor] Buttons

2013-05-27 Thread Alan Gauld

On 27/05/13 15:17, Jack Little wrote:

Is there a way to make buttons a little like a raw_input in the context
when the user presses the button, the program performs a function?


Yes, but its a lot more complicated than raw_input.

See the GUI topic of my tutorial for examples.

Also check out the EasyGUI package for an easy way to add GUI style 
dialog boxes to an otherwise console based app. (see my Talking to the 
User topic in my V3 tutorial for more on EasyGUI)


HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Buttons automatically executing

2005-06-15 Thread Danny Yoo


On Wed, 15 Jun 2005, Phillip Hart wrote:

 Thanks for taking the time to read this.

 Excuse me if this falls under the boundaries of a newbie question, as
 I am a self-taught programmer.

Hi Phillip,

It's a newbie question.  But that's perfectly ok.  *grin*


 While using Tkinter to create buttons, something unexpected happens when
 the button commands call functions. Namely, when I run the following, it
 immediately executes the print statements without the button ever being
 pressed. Additionally, pressing the button once the Tk window is up will
 not activate the button.

The issue is that there's a difference between calling a function, and
getting a function value.  Let's go through an example to get started:


For example, let's say that we do have that 'location' function defined:

###
 def location(x, y):
... print I am in row, x, and column, y
...
###



A function value is what we get when we don't use parentheses:

###
 location
function location at 0x64c30
###


And this thing can be handled just like any other value in Python: we can
pass it around and put it in lists:

###
 somelist = [location, location, location]
 somelist
[function location at 0x64c30, function location at 0x64c30, function
location at 0x64c30]
###



One neat thing that you already know about functions is that they can be
called.  You're used to doing something like this:

###
 location(3, 4)
I am in row 3 and column 4
###


but we can also do something like this:

###
 somelist[0]
function location at 0x64c30
 somelist[0](2, 3)
I am in row 2 and column 3
###

That is, 'somelist[0]' is a function value, and when we use parens next to
it '(2, 3)', then we fire off that function value with those two
arguments.

Does this make sense so far?



When we're constructing a button:

b1=Button(can,bg=black,image=bimage,command=location(0,0))

we should be careful to pass a function value as the 'command': if we use
parens prematurely, what ends up happening is that command gets set to the
return value of calling 'location(0, 0)'.


It looks we want to set 'command' to a function value that, when called,
does a 'location(0,0)'.  We can do that:

###
def reset():
location(0, 0)
b1 = Button(can,bg=black,image=bimage,command=reset)
###

'reset' is a function that, when called, does location(0, 0).


Please feel free to ask more questions about this.  Good luck to you!

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] buttons, scrollbar, tkinter

2005-05-18 Thread jfouhy
Quoting Ron Alvarado [EMAIL PROTECTED]:

 Is there any way to change this to put in a column of buttons and it
 will scroll like it does now. I've tried but when I put in the buttons the
 scrollbar just grows with all the buttons and won't do anything.

I'm not exactly sure what you're after here ...

You can't put buttons into a Listbox.  A Listbox will only take strings.

You can attach a scrollbar to a Frame and pack a bunch of buttons into that.

But I find the easiest solution to making scrolling things is to get Pmw:
http://pmw.sourceforge.net/ .  A Pmw.ScrolledFrame will probably do what you
want with very little effort on your part.

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor