Re: [Tutor] Misunderstanding the Entry Widget

2009-03-09 Thread Wayne Watson
Title: Signature.html




Very good. Thanks. 
(I posted this about 20 hours ago with an image of my screen output. It
appears it's waiting for moderator approval, so I'm posting it again
w/o the image. Maybe the image will show up later. I think some
progress can be made with out it. )

Well, the idea of using Entry1,2 logic hit a snag. First, the program
has an oddity that I do not understand. Here's the problem area. See
the highlighted code stuff in purple and bold at the bottom. Above
that code, it's forming buttons and so on with no return object from
anywhere, then "entry = Entry(master, width=10, ..." appears. I put
some debug code in there, and ended it wih a return of entry before
20-30 lines of code using Label, etc. that use no assignment to any
object. After that is the original return entry. It's puzzling why it
returns just entry. I suspect that should cause the return to be a
OperationalSettingsDialog object; however, when I print the object and
its type, they are None, and type 'NoneType'. 

REMOVED IMAGE HERE. It shows the None-NoneType msg and other Python
msgs. 

class OperationalSettingsDialog(tkSimpleDialog.Dialog):

 def __init__(self, parent, sdict):
 self.sdict = sdict
 print "Set OSDiag sdict"
 print
 tkSimpleDialog.Dialog.__init__(self, parent)
 
 def body(self,master):
 self.title("Operational Settings")

 print "body from OSDialog, self =", self, "type =", type(self)
 self.colorVar = IntVar()
 Radiobutton( master, text="Gray Scale",
 value=1, variable=self.colorVar).grid(row=0,
sticky=W)
 Radiobutton( master, text="Pseudo Color",
 value=2, variable=self.colorVar).grid(row=1,
sticky=W)
 self.colorVar.set( self.sdict["color"] )

 self.post_event_stackVar = IntVar()
 Checkbutton( master, text="Make long exposure after each event",
 variable=self.post_event_stackVar).grid(row=2,
sticky=W)
 self.post_event_stackVar.set( self.sdict["post_event_stack"] )

 self.show_real_timeVar = IntVar()
 Checkbutton( master, text="Show event as it is being received",
 variable=self.show_real_timeVar).grid(row=3,
sticky=W)
 self.show_real_timeVar.set( self.sdict["show_real_time"] )

 Label( master, text="Playback Slowdown: ").grid(row=4, stick=W)
 self.slowdownVar = StringVar()

# entry = Entry(master, width=10,
textvariable=self.slowdownVar).grid(row=4, column=1)
 entry = Entry(master, width=10).grid(row=4, column=1)
 print "entry, entry type:", entry,type(entry)
 entry.insert(0,self.slowdown)
 slowdown = entry
 print "holly cow: ",slowdown
 #self.slowdownVar.set( "%d" % self.sdict["slowdown"] )
 return entry

Alan Gauld wrote:

"Alan Gauld" alan.ga...@btinternet.com
wrote 
  
Yep, when I bowed of programming long ago,
I had Ousterhout's 

It was a good book in its day but is now well overdue an update. 
  
  
And lo and behold, listed on Amazon is the 2nd edition due in August
2009! 
  
How's that for service :-) 
  
BTW I also noticed that there is also now an O'Reilly pocket reference
which might be even more useful to Python Tkinter users than the
Nutshell - smaller and cheaper and even more terse! Although it doesn't
appear to cover Tix... 
  
Alan G. 
  
  
___ 
Tutor maillist - Tutor@python.org 
  http://mail.python.org/mailman/listinfo/tutor
  
  


-- 


   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)


In mathematics you don't understand things. 
 You just get used to them. -- John Von Neumann
(P.S. The same is true in life.)




Web Page: www.speckledwithstars.net/



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


Re: [Tutor] Misunderstanding the Entry Widget

2009-03-09 Thread Wayne Watson
Title: Signature.html




I had commented out
# entry = Entry(master, width=10,
textvariable=self.slowdownVar).grid(row=4, column=1), which had worked
fine previously to my changes.
I added your two statements after remarking 
entry = Entry(master, width=10).grid(row=4, column=1)


IDLE  the Command prompt window produced, which was really what I
was showing in the image that I removed:

Exception in Tkinter callback
Traceback (most recent call last):
 File "C:\Python25\Lib\lib-tk\Tkinter.py", line 1403, in __call__
 return self.func(*args)
 File
"C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser-Utilities\sentuser\sentuserNC25-Dev5.py",
line 579, in OperationalSettings
 dialog = OperationalSettingsDialog( self.master, set_loc_dict )
 File
"C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser-Utilities\sentuser\sentuserNC25-Dev5.py",
line 84, in __init__
 tkSimpleDialog.Dialog.__init__(self, parent)
 File "C:\Python25\lib\lib-tk\tkSimpleDialog.py", line 64, in __init__
 self.initial_focus = self.body(body)
 File
"C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser-Utilities\sentuser\sentuserNC25-Dev5.py",
line 115, in body
 entry.insert(0,self.slowdown)
AttributeError: OperationalSettingsDialog instance has no attribute
'slowdown'

Kent Johnson wrote:

  On Mon, Mar 9, 2009 at 8:30 AM, Wayne Watson
sierra_mtnv...@sbcglobal.net wrote:

  
  
 entry = Entry(master, width=10).grid(row=4, column=1)

  
  
You have to write this as
entry = Entry(master, width=10)
entry.grid(row=4, column=1)

The grid() method returns None, that is why entry is None.

Kent

  


-- 


   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)


In mathematics you don't understand things. 
 You just get used to them. -- John Von Neumann
(P.S. The same is true in life.)




Web Page: www.speckledwithstars.net/



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


Re: [Tutor] Misunderstanding the Entry Widget

2009-03-09 Thread Wayne Watson
Title: Signature.html




On a branch off this thread, I've mentioned a problem with this
approach. It seems right, but I haven't bridged it yet. Do you have
some simple Tk Python code that shows how to do this?

Alan Gauld wrote:

"Wayne Watson" sierra_mtnv...@sbcglobal.net wrote
  
  
  Signature.htmlAnother thought occurred to me
about this situation.

Suppose I have a dialog with two Entry objects in a dialog object
called TwoEntries:

 entry1 = Entry(master, width=10).grid(row=4, column=1)

 entry2 = Entry(master, width=10).grid(row=5, column=1)

and I do not use a StringVar to return the values entered.

Is it possible to reach inside TwoEntries, after returning from it,

and grab entry1 and 2? It would seem so if the call was
dialog=TwoEntries(...).

  
  
Sure, just use
  
  
x = dialog.entry1.get()
  
y = dialog.entry2.get()
  
  
There really is nothing special going on.
  
  
  I have no idea of the history of these
variables, but they have

very limited descriptions and examples.

  
  
I assume because they have a very simple and specific purpose.
  
There is probably more on them if you look at the original Tcl/Tk
  
documentation. Remember Tkinter is just a wrapper arpund Tcl/Tkl
  
and Tk has been around for a long time (20 years now)
  
  
Alan G. 
  
___
  
Tutor maillist - Tutor@python.org
  
http://mail.python.org/mailman/listinfo/tutor
  
  


-- 


   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)


In mathematics you don't understand things. 
 You just get used to them. -- John Von Neumann
(P.S. The same is true in life.)




Web Page: www.speckledwithstars.net/




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


Re: [Tutor] Misunderstanding the Entry Widget

2009-03-08 Thread Alan Gauld


Wayne Watson sierra_mtnv...@sbcglobal.net wrote


Signature.htmlAnother thought occurred to me about this situation.
Suppose I have a dialog with two Entry objects in a dialog object 
called TwoEntries:

   entry1 = Entry(master, width=10).grid(row=4, column=1)
   entry2 = Entry(master, width=10).grid(row=5, column=1)
and I do not use a StringVar to return the values entered.
Is it possible to reach inside TwoEntries, after returning from it,
and grab entry1 and 2? It would seem so if the call was 
dialog=TwoEntries(...).


Sure, just use

x = dialog.entry1.get()
y = dialog.entry2.get()

There really is nothing special going on.


 I have no idea of the history of these variables, but they have
very limited descriptions and examples.


I assume because they have a very simple and specific purpose.
There is probably more on them if you look at the original Tcl/Tk
documentation. Remember Tkinter is just a wrapper arpund Tcl/Tkl
and Tk has been around for a long time (20 years now)

Alan G. 



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


Re: [Tutor] Misunderstanding the Entry Widget

2009-03-08 Thread Wayne Watson
Title: Signature.html




Thanks. Your statement is reassuring. Without trying to give my self a
pat on the back, exactly written as I figured. It seems so very
obvious, but the lack of attention to using that style makes one wonder
why it isn't commonly found anywhere in the discussion of more complex
collection of widgets (see my other comments below). In my case, really
following the author's (of 2000 lines of code I have) makes me wonder
why he didn't do it that way. I suspect the answer is he had recently
taken a Python class before writing it, and was following what simply
was taught to get this program completed. (It is not a classroom
program.) I know he put it together quickly, and did quite a
spectacular job of writing the code and interfacing it to some complex
h/w. 

Alan Gauld wrote:

"Wayne Watson" sierra_mtnv...@sbcglobal.net wrote
  
  
  Signature.htmlAnother thought occurred to me
about this situation.

Suppose I have a dialog with two Entry objects in a dialog object
called TwoEntries:

 entry1 = Entry(master, width=10).grid(row=4, column=1)

 entry2 = Entry(master, width=10).grid(row=5, column=1)

and I do not use a StringVar to return the values entered.

Is it possible to reach inside TwoEntries, after returning from it,

and grab entry1 and 2? It would seem so if the call was
dialog=TwoEntries(...).

  
  
Sure, just use
  
  
x = dialog.entry1.get()
  
y = dialog.entry2.get()
  
  
There really is nothing special going on.
  
  
  I have no idea of the history of these
variables, but they have

very limited descriptions and examples.

  
  
I assume because they have a very simple and specific purpose.
  
There is probably more on them if you look at the original Tcl/Tk
  
documentation. Remember Tkinter is just a wrapper arpund Tcl/Tkl
  
and Tk has been around for a long time (20 years now)
  

Yep, when I bowed of programming long ago, I had Ousterhout's
(something like that) book, and finally sold it on Amazom 5 years ago
with the thought I have no plan to use it. Ha! The same thing with
Linux/Unix. Five years ago, I marginally used it, and swore off it
after having it heavily 10 years before. Two weeks ago, I found a
meteor analysis program written in C and to uncover it was of use have
(temporarily) climbed back on Linux. I manged to get a clunky old PC
back that I gave a friend 3 years ago to put RH on. He had since gone
on to a laptop, and put the PC in his garage. Just can't shake the
computer habit. :-)

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


-- 


   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)


In mathematics you don't understand things. 
 You just get used to them. -- John Von Neumann
(P.S. The same is true in life.)




Web Page: www.speckledwithstars.net/




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


Re: [Tutor] Misunderstanding the Entry Widget

2009-03-08 Thread Alan Gauld

Wayne Watson sierra_mtnv...@sbcglobal.net wrote


Yep, when I bowed of programming long ago, I had Ousterhout's
(something like that) book, and finally sold it on Amazom 5 years 
ago


It was a good book in its day but is now well overdue an update.

The book I'd recommend getting is Tcl/Tk in a Nutshell from O'Reilly
Its only a reference but it covers Tk and Tix. There is hardly any 
Python
docs for Tix although it is now part of the standard library. 
(Actually

I think Tkinter needs an update too, there seem to be quite a few
new Tk widgets that are not available in Tkinter... or is it just that
they are not documented? I must have a poke around in v2.5...
But the Nutshell seems to cover all the stuff that is in Tkinter)

You can get a used Nutshell for around $6 via Amazon (and it
covers expect too should you ever dabble with pyExpect).

[ But note: for serious Tcl users the best book is Welsh's offering
 the Niutshell is just a reference that translates fairly easily to 
Tkinter/Tix]


On Linux, I started using it in 1993 with RedHat 2 and Slackware 3.
I dropped out for a spell then came back to it around Slackware 7
and Mandrake (now Mandriva) 3? But then I bought a Mac iBook and
discovered cygwin and my current Linux box (Suse 9?) is lying idle.
It only gets booted when I want to test some web things because
it runs apache and Turbo Gears.

Although I do now have an Asus Eee mini laptop with Linux and I'm
using that to do some stuff now and then.

Alan G. 



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


Re: [Tutor] Misunderstanding the Entry Widget

2009-03-08 Thread Alan Gauld


Alan Gauld alan.ga...@btinternet.com wrote 


Yep, when I bowed of programming long ago, I had Ousterhout's

It was a good book in its day but is now well overdue an update.


And lo and behold, listed on Amazon is the 2nd edition due 
in August 2009!


How's that for service :-)

BTW I also noticed that there is also now an O'Reilly pocket 
reference which might be even more useful to Python Tkinter 
users than the Nutshell - smaller and cheaper and even more 
terse! Although it doesn't appear to cover Tix...


Alan G.


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


Re: [Tutor] Misunderstanding the Entry Widget

2009-03-08 Thread Wayne Watson




Sounds like the O'Reilly book might be worth it. I have an interlibrary
loan request out for a highly recommended Tk/Tcl book. I tried Cygwin
about 5 years ago, and it just didn't cut it. Odd problems. It may be
worth a shot again when I can free up some time. 

Alan Gauld wrote:
"Wayne
Watson" sierra_mtnv...@sbcglobal.net
wrote 
  
  Yep, when I bowed of programming long ago, I
had Ousterhout's 
(something like that) book, and finally sold it on Amazom 5 years ago 
  
  
It was a good book in its day but is now well overdue an update. 
  
The book I'd recommend getting is Tcl/Tk in a Nutshell from O'Reilly 
Its only a reference but it covers Tk and Tix. There is hardly any
Python 
docs for Tix although it is now part of the standard library. (Actually
  
I think Tkinter needs an update too, there seem to be quite a few 
new Tk widgets that are not available in Tkinter... or is it just that 
they are not documented? I must have a poke around in v2.5... 
But the Nutshell seems to cover all the stuff that is in Tkinter) 
  
You can get a used Nutshell for around $6 via Amazon (and it 
covers expect too should you ever dabble with pyExpect). 
  
[ But note: for serious Tcl users the best book is Welsh's offering 
the Niutshell is just a reference that translates fairly easily to
Tkinter/Tix] 
  
On Linux, I started using it in 1993 with RedHat 2 and Slackware 3. 
I dropped out for a spell then came back to it around Slackware 7 
and Mandrake (now Mandriva) 3? But then I bought a Mac iBook and 
discovered cygwin and my current Linux box (Suse 9?) is lying idle. 
It only gets booted when I want to test some web things because 
it runs apache and Turbo Gears. 
  
Although I do now have an Asus Eee mini laptop with Linux and I'm 
using that to do some stuff now and then. 
  
Alan G. 
  
___ 
Tutor maillist - Tutor@python.org 
  http://mail.python.org/mailman/listinfo/tutor
  
  


-- 

Signature.html
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)


In mathematics you don't understand things. 
 You just get used to them. -- John Von Neumann
(P.S. The same is true in life.)




Web Page: www.speckledwithstars.net/



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


Re: [Tutor] Misunderstanding the Entry Widget

2009-03-08 Thread Alan Gauld

Alan Gauld alan.ga...@btinternet.com wrote


I think Tkinter needs an update too, there seem to be quite a few
new Tk widgets that are not available in Tkinter... or is it just 
that

they are not documented? I must have a poke around in v2.5...


I spoke too soon, its just the documentation needs an update the
newer widgets are supported - at least paned window and Spinbox
are, I didn't try any others. But you will need to look in the Tcl/Tk 
docs

to find out how to use them!

Here is the best site I know. It doesn't give Tkinter examples
but does give Perl examples, which are pretty similar in style.

http://www.tkdocs.com/tutorial/morewidgets.htm

It also looks like we will get the new themed widgets in Python 2.7
and 3.1 which means Tkinter will no longer be the ugly duckling
of Python GUI toolkits! Hooray! :-)

HTH,

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



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


Re: [Tutor] Misunderstanding the Entry Widget

2009-03-07 Thread Alan Gauld


Wayne Watson sierra_mtnv...@sbcglobal.net wrote 

Can you easily construct a simple example where they are 
absolutely necessary, or at least provide a situation where 
they are necessary?


I don't think you can. They are a convenience feature 
not a necessity. But the same can be said of standard dialogs, 
message boxes etc. You could build all of those from basic 
widgets but it woulfd be a pain. Sometimes Control variables 
save you some pain.


Personally I don't bother with them much but others like them.

Alan G

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


Re: [Tutor] Misunderstanding the Entry Widget

2009-03-07 Thread Wayne Watson
Title: Signature.html




I have no idea of the history of these variables, but they have very
limited descriptions and examples. Maybe someone like Grayson goes into
detail on them. Looking at the program I'm concerned about, it almost
looks like the use is a learned response to dealing with the widgets
used. That's OK. I just wanted to make sure I wasn't overlooking
something. It provided a helpful interlude. :-)

Alan Gauld wrote:

"Wayne Watson" sierra_mtnv...@sbcglobal.net
wrote  
  
  Can you easily construct a simple example
where they are absolutely necessary, or at least provide a situation
where they are necessary? 
  
  
I don't think you can. They are a convenience feature not a necessity.
But the same can be said of standard dialogs, message boxes etc. You
could build all of those from basic widgets but it woulfd be a pain.
Sometimes Control variables save you some pain. 
  
Personally I don't bother with them much but others like them. 
  
Alan G 
  
___ 
Tutor maillist - Tutor@python.org 
  http://mail.python.org/mailman/listinfo/tutor
  
  


-- 


   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)


In mathematics you don't understand things. 
 You just get used to them. -- John Von Neumann
(P.S. The same is true in life.)




Web Page: www.speckledwithstars.net/



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


Re: [Tutor] Misunderstanding the Entry Widget

2009-03-07 Thread Wayne Watson
Title: Signature.html




Another thought occurred to me about this situation. Suppose I have a
dialog with two Entry objects in a dialog object called TwoEntries:
 entry1 = Entry(master, width=10).grid(row=4, column=1)
 entry2 = Entry(master, width=10).grid(row=5, column=1) 
and I do not use a StringVar to return the values entered. Is it
possible to reach inside TwoEntries, after returning from it, and grab
entry1 and 2? It would seem so if the call was dialog=TwoEntries(...).

Wayne Watson wrote:

  
I have no idea of the history of these variables, but they have very
limited descriptions and examples. Maybe someone like Grayson goes into
detail on them. Looking at the program I'm concerned about, it almost
looks like the use is a learned response to dealing with the widgets
used. That's OK. I just wanted to make sure I wasn't overlooking
something. It provided a helpful interlude. :-)
  
Alan Gauld wrote:
  
"Wayne Watson" sierra_mtnv...@sbcglobal.net
wrote  

Can you easily construct a simple example
where they are absolutely necessary, or at least provide a situation
where they are necessary? 


I don't think you can. They are a convenience feature not a necessity.
But the same can be said of standard dialogs, message boxes etc. You
could build all of those from basic widgets but it woulfd be a pain.
Sometimes Control variables save you some pain. 

Personally I don't bother with them much but others like them. 

Alan G 

___ 
Tutor maillist - Tutor@python.org

http://mail.python.org/mailman/listinfo/tutor


  
  
  -- 
  
  
 Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)


In mathematics you don't understand things. 
 You just get used to them. -- John Von Neumann
(P.S. The same is true in life.)

  
  
  
Web Page: www.speckledwithstars.net/
  
  

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


-- 

Signature.html
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)


In mathematics you don't understand things. 
 You just get used to them. -- John Von Neumann
(P.S. The same is true in life.)




Web Page: www.speckledwithstars.net/




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


Re: [Tutor] Misunderstanding the Entry Widget

2009-03-06 Thread Alan Gauld


Wayne Watson sierra_mtnv...@sbcglobal.net wrote 

Apparently Entry does not have a callback. 


Thats the magic of Control Variables. They automatically 
get populated when the user enters data into the Entry widget.


But since Entry widgets are usually part if a form and there 
will be several of them its more useful to wait for the whole 
form to be complteed and then hit a Submit button. The 
button handler can then read all of the Entry fields using get()


So you are right that there is no callback per se except for 
the auto settigh of control variables, but you can't trigger 
an action based on that. However you can of course bind 
an event to the Entry box such as keypress, mouse over etc.
and the event can trigger an action, so in your example you 
could bind a carriage return keystroke to some action.


See the event handling topic in my tutorial for an example 
of binding a specific key to an event.


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

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


Re: [Tutor] Misunderstanding the Entry Widget

2009-03-06 Thread Kent Johnson
On Thu, Mar 5, 2009 at 10:52 PM, Wayne Watson
sierra_mtnv...@sbcglobal.net wrote:
 Apparently Entry does not have a callback. It seems as though it should. If
 one enters data into it and presses Return, then it would be good to know
 what the data is, so it can be used elsewhere. However, that's not the way
 it works. One seems to need a button or some other widget to make it
 happen*. So what's the game with it?

You can bind a Return event to an Entry widget. Here is a simple example:

from Tkinter import *

def showText(evt):
print 'Text is:', text.get('0.0', END)
return 'break'  # Prevent the event from propagating to the Text widget

root = Tk()
text = Text()

# This line binds the showText handler to the Return key event
text.bind('Return', showText)
text.pack()
root.mainloop()

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


Re: [Tutor] Misunderstanding the Entry Widget

2009-03-06 Thread Wayne Watson
Title: Signature.html




Control variables. What is the difference between IntVar, BooleanVar,
StringVar, and DoubleVar? For example, in the program below, it looks
like I get the same result usint IntVar or StringVar. It almost appears
the usage depends on what widget one uses: Entry, RadioButton,
CheckBox, ...

===begin=
from Tkinter import *
# Use of control variables

def mycallback():
 print "User entered:" , e.get()
 print "Operationg by 2 gives: ", e.get()*2

master = Tk()

v=StringVar()
#v=IntVar()
print v,type(v)
e = Entry(master,textvariable=v)
e.pack()
b = Button(master, text="Push to Print", width=10, command=mycallback)
b.pack()
e.focus_set()

v.set(123)

mainloop() 
=End=


Alan Gauld wrote:

"Wayne Watson" sierra_mtnv...@sbcglobal.net wrote 
  Apparently Entry does not have a callback. 
  
Thats the magic of Control Variables. They automatically get populated
when the user enters data into the Entry widget.
  
  
But since Entry widgets are usually part if a form and there will be
several of them its more useful to wait for the whole form to be
complteed and then hit a Submit button. The button handler can then
read all of the Entry fields using get()
  
  
So you are right that there is no callback per se except for the auto
settigh of control variables, but you can't trigger an action based on
that. However you can of course bind an event to the Entry box such as
keypress, mouse over etc.
  
and the event can trigger an action, so in your example you could bind
a carriage return keystroke to some action.
  
  
See the event handling topic in my tutorial for an example of binding a
specific key to an event.
  
  


-- 


   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)


In mathematics you don't understand things. 
 You just get used to them. -- John Von Neumann
(P.S. The same is true in life.)




Web Page: www.speckledwithstars.net/




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


Re: [Tutor] Misunderstanding the Entry Widget

2009-03-06 Thread Kent Johnson
On Fri, Mar 6, 2009 at 7:15 AM, Wayne Watson
sierra_mtnv...@sbcglobal.net wrote:
 Control variables. What is the difference between IntVar,  BooleanVar,
 StringVar,  and DoubleVar?

The difference is the type of value returned by get().

  For example, in the program below, it looks like
 I get the same result usint IntVar or StringVar. It almost appears the usage
 depends on what widget one uses: Entry, RadioButton, CheckBox, ...

 ===begin=
 from Tkinter import *
 # Use of control variables

 def mycallback():
     print User entered: , e.get()
     print Operationg by 2 gives: , e.get()*2

Change the above to use v.get(). e.get() has nothing to do with the var.

 master = Tk()

 v=StringVar()
 #v=IntVar()
 print v,type(v)

Try this:
print v, type(v), type(v.get())

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


Re: [Tutor] Misunderstanding the Entry Widget

2009-03-06 Thread Wayne Watson




I've just got to stop using one letter for variables, especially ones
that sound alike! :-)

Other than v tracking every value change made, did I gain anything by
using it? It seems to me that control variables are of marginal use. I
might have thought they were necessary for use with scale widgets, but
I'm looking at an example that says otherwise. Can you easily construct
a simple example where they are absolutely necessary, or at least
provide a situation where they are necessary?

Kent Johnson wrote:

  On Fri, Mar 6, 2009 at 7:15 AM, Wayne Watson
sierra_mtnv...@sbcglobal.net wrote:
  
  
Control variables. What is the difference between IntVar, BooleanVar,
StringVar, and DoubleVar?

  
  
The difference is the type of value returned by get().

  
  
 For example, in the program below, it looks like
I get the same result usint IntVar or StringVar. It almost appears the usage
depends on what widget one uses: Entry, RadioButton, CheckBox, ...

===begin=
from Tkinter import *
# Use of control variables

def mycallback():
 print "User entered:" , e.get()
 print "Operationg by 2 gives: ", e.get()*2

  
  
Change the above to use v.get(). e.get() has nothing to do with the var.

  
  
master = Tk()

v=StringVar()
#v=IntVar()
print v,type(v)

  
  
Try this:
print v, type(v), type(v.get())

Kent

  


-- 

Signature.html
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)


In mathematics you don't understand things. 
 You just get used to them. -- John Von Neumann
(P.S. The same is true in life.)




Web Page: www.speckledwithstars.net/




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


Re: [Tutor] Misunderstanding the Entry Widget

2009-03-06 Thread Kent Johnson
On Fri, Mar 6, 2009 at 11:26 AM, Wayne Watson
sierra_mtnv...@sbcglobal.net wrote:
 I've just got to stop using one letter for variables, especially ones that
 sound alike! :-)

 Other than v tracking every value change made, did I gain anything by using
 it? It seems to me that control variables are of marginal use. I might have
 thought they were necessary for use with scale widgets, but I'm looking at
 an example that says otherwise. Can you easily construct a simple example
 where they are absolutely necessary, or at least provide a situation where
 they are necessary?

You need a variable to get the state of a Checkbutton. Variables would
be helpful if you had multiple controls displaying the same value.
They might give a useful decoupling between the GUI and other clients
of the data; they are a mini-model, in the Model-View-Controller
sense.

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


[Tutor] Misunderstanding the Entry Widget

2009-03-05 Thread Wayne Watson
Title: Signature.html




Apparently Entry does not have a callback. It seems as though it
should. If one enters data into it and presses Return, then it would be
good to know what the data is, so it can be used elsewhere. However,
that's not the way it works. One seems to need a button or some other
widget to make it happen*. So what's the game with it?

* I have looked at 3 Entry examples on the web that appear to be well
written, and none of them really return anything, although they
supposedly should print the entry data once their button is pressed.
Well, OK, one does, but only after I had to remove the dash from the
name and replace it with an underscore. Whoops, that one doesn't really
work either. 
-- 


   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)


In mathematics you don't understand things. 
 You just get used to them. -- John Von Neumann
(P.S. The same is true in life.)




Web Page: www.speckledwithstars.net/



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