A Simple Tkinter Control Program--Slight Problem

Discussion in 'Python' started by W. eWatson, Mar 4, 2009.

  1. W. eWatson

    W. eWatson Guest

    Here's what I think the author meant in discussing a control variable sample
    program. <http://effbot.org/tkinterbook/entry.htm>

    from Tkinter import *

    v=Tk.StringVar()

    e = Entry(master, textvariable=v)
    e.pack()
    e.focus_set()

    v.set("a default value")
    s = v.get()

    mainloop()

    The problem is that Python objects to v=.
    v=Tk.StringVar()
    AttributeError: class Tk has no attribute 'StringVar'

    What corrects this?
    --
    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. eWatson, Mar 4, 2009
    #1
    1. Advertising

  2. On Wed, 04 Mar 2009 10:09:10 -0800, W. eWatson wrote:

    > Here's what I think the author meant in discussing a control variable
    > sample program. <http://effbot.org/tkinterbook/entry.htm>
    >
    > from Tkinter import *
    >
    > v=Tk.StringVar()
    >
    > e = Entry(master, textvariable=v)
    > e.pack()
    > e.focus_set()
    >
    > v.set("a default value")
    > s = v.get()
    >
    > mainloop()
    >
    > The problem is that Python objects to v=.
    > v=Tk.StringVar()
    > AttributeError: class Tk has no attribute 'StringVar'
    >
    > What corrects this?


    Learn how to copy code 1:1 from a web page or understand Python's import
    and namespaces.

    Ciao,
    Marc 'BlackJack' Rintsch
     
    Marc 'BlackJack' Rintsch, Mar 4, 2009
    #2
    1. Advertising

  3. W. eWatson

    W. eWatson Guest

    Marc 'BlackJack' Rintsch wrote:
    > On Wed, 04 Mar 2009 10:09:10 -0800, W. eWatson wrote:
    >
    >> Here's what I think the author meant in discussing a control variable
    >> sample program. <http://effbot.org/tkinterbook/entry.htm>
    >>
    >> from Tkinter import *
    >>
    >> v=Tk.StringVar()
    >>
    >> e = Entry(master, textvariable=v)
    >> e.pack()
    >> e.focus_set()
    >>
    >> v.set("a default value")
    >> s = v.get()
    >>
    >> mainloop()
    >>
    >> The problem is that Python objects to v=.
    >> v=Tk.StringVar()
    >> AttributeError: class Tk has no attribute 'StringVar'
    >>
    >> What corrects this?

    >
    > Learn how to copy code 1:1 from a web page or understand Python's import
    > and namespaces.
    >
    > Ciao,
    > Marc 'BlackJack' Rintsch

    It wasn't a matter of copying. I had experimented with the code and found a
    note that suggested using Tk, and another way of getting the job. It didn't
    work. I missed removing it (Tk).

    "Never assume!"--Spencer Tracy, cautioning Katharine Hepburn in a puzzle he
    is about to give her in the movie Desk Set.

    Here's the segment the author singled out:

    v = StringVar()
    e = Entry(master, textvariable=v)
    e.pack()

    v.set("a default value")
    s = v.get()


    --
    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. eWatson, Mar 4, 2009
    #3
  4. W. eWatson

    W. eWatson Guest

    I like to see closure on a thread. This should do it.

    from Tkinter import *
    # Use of control variables and callbacks

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

    master = Tk()

    #v=StringVar()
    v=IntVar()
    print v,type(v)
    print v, type(v), type(v.get())
    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()


    --
    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. eWatson, Mar 6, 2009
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Debo
    Replies:
    3
    Views:
    632
    Swampmonster
    Dec 12, 2004
  2. Thomas Womack

    slight csv misbehavior under Windows

    Thomas Womack, Aug 18, 2003, in forum: Python
    Replies:
    1
    Views:
    405
  3. JNY

    slight rounding problem

    JNY, Jan 11, 2005, in forum: C Programming
    Replies:
    2
    Views:
    333
    Joe Wright
    Jan 12, 2005
  4. JNY

    slight rounding problem

    JNY, Jan 12, 2005, in forum: C Programming
    Replies:
    2
    Views:
    304
    Keith Thompson
    Jan 12, 2005
  5. wannieb

    Slight problem with script

    wannieb, Feb 27, 2006, in forum: Javascript
    Replies:
    0
    Views:
    117
    wannieb
    Feb 27, 2006
Loading...

Share This Page