What is intvar?

W

W. eWatson

I'm looking at someone's code in which invar() is used fairly often.
Apparently, it's a Tkinter method. Here's a use:
def body(self,master):
self.title("Display Settings")

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)
...

What is the need for this use? It looks like some sort of initialization for
a widget.

I've scoured the internet with Google, and have yet to find a simple
explanation of what it's used for.
--
W. eWatson

(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: <www.speckledwithstars.net/>
 
C

Chris Rebert

I'm looking at someone's code in which invar() is used fairly often.
Apparently, it's a Tkinter method. Here's a use:
def body(self,master):
self.title("Display Settings")

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)
...

What is the need for this use? It looks like some sort of initialization for
a widget.

I've scoured the internet with Google, and have yet to find a simple
explanation of what it's used for.

Search for IntVar on http://docs.python.org/library/tkinter.html and
read the enclosing section.
I think it's basically used to propagate changes to the GUI and
convert values (in this case, ints) between Python and Tk.

Cheers,
Chris
 
R

Rhodri James

I'm looking at someone's code in which invar() is used fairly often.
Apparently, it's a Tkinter method. Here's a use:
def body(self,master):
self.title("Display Settings")

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)
...

What is the need for this use? It looks like some sort of initialization
for a widget.

Chris has already pointed you to the Tkinter documentation, which is a
good start but a little less than clear in places.

What your example code does is to associate self.colorVar with the set
of radio buttons. This isn't just initialisation, it's a full reflection
of the current state.

self.colorVar.get() returns the "value" parameter that you gave to the
radio button which is currently selected (so, for example, if it returns
1 you know that the "Grey Scale" button is the one selected). Similarly
self.colorVar.set(n) selects whichever radio button has the "value" which
matches n (so self.colorVar.set(2) selects the "Pseudo Color" button).

IntVar and StringVar (and DoubleVar if you must :) are basically the
easy way of dynamically reading and changing the values in various
entry widgets, the text on buttons, and so on.
 
W

W. eWatson

r said:
Thanks to all for the reference and tips.

--
W. eWatson

(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: <www.speckledwithstars.net/>
 
W

W. eWatson

W. eWatson said:
Thanks to all for the reference and tips.
tkinterbook is easy to follow, but it seems to have been abandoned in 2005.
Did it appear in another guise somewhere else?

--
W. eWatson

(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: <www.speckledwithstars.net/>
 
S

Steve Holden

W. eWatson said:
tkinterbook is easy to follow, but it seems to have been abandoned in
2005. Did it appear in another guise somewhere else?
There hasn't been a lot of development on Tkinter in the intervening
period. It's a mature system, so there has been no need to update the
documentation.

regards
Steve
 
W

W. eWatson

Steve said:
There hasn't been a lot of development on Tkinter in the intervening
period. It's a mature system, so there has been no need to update the
documentation.

regards
Steve
Unfortunately, the author seems to have stopped mid-stream. I see a fair
number of FIXMEs in it. It looks like the New Mexico pdf is a fitting
replacement. Perhaps Intro to Tkinter should be scrapped?

Another of the author's writings, on PIL, looks good as a pdf, but is
missing a TOC. Maybe some pdf knowledgeable person knows how to generate one
easily.

--
W. eWatson

(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: <www.speckledwithstars.net/>
 
R

r

W. eWatson,

I contacted the author of New Mexico Techs "Introduction to Tkinter" a
couple of weeks ago. He is going to update the reference material with
a few missing widgets and some info on Photo and Bitmap classes. I
really love the NMT layout and use it quite often. Fredricks
Tkinterbook is more detail but lacking in navigation. I swing back and
forth between both sites.
 
W

W. eWatson

r said:
W. eWatson,

I contacted the author of New Mexico Techs "Introduction to Tkinter" a
couple of weeks ago. He is going to update the reference material with
a few missing widgets and some info on Photo and Bitmap classes. I
really love the NMT layout and use it quite often. Fredricks
Tkinterbook is more detail but lacking in navigation. I swing back and
forth between both sites.
Good. Thanks. I think Lundh might have taken his material to book form.

I might be repeating myself here, but If anyone has pdf experience, and
could provide page numbers and maybe a TOC for some of Lundh's
contributions, that would be helpful.

--
W. eWatson

(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: <www.speckledwithstars.net/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,046
Members
48,769
Latest member
Clifft

Latest Threads

Top