Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8577 > unrolled thread

get() attribute for Entry in Tkinter

Started byRobert Upton <yybar85712@gmail.com>
First post2011-06-29 12:15 -0700
Last post2011-06-29 23:35 +0200
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  get() attribute for Entry in Tkinter Robert Upton <yybar85712@gmail.com> - 2011-06-29 12:15 -0700
    Re: get() attribute for Entry in Tkinter Peter Otten <__peter__@web.de> - 2011-06-29 23:35 +0200

#8577 — get() attribute for Entry in Tkinter

FromRobert Upton <yybar85712@gmail.com>
Date2011-06-29 12:15 -0700
Subjectget() attribute for Entry in Tkinter
Message-ID<3e0341d0-e045-4f93-a816-1b304de4cd80@h12g2000pro.googlegroups.com>
Dear Pythoners,

I am in the process of generating a simple GUI that wants to read a
string and print it to the terminal after engaging a button.  I am
running into a problem where Python says it does not understand the
get() attribute for Entry.  My code is very simple and is shown
below.  Please provide comments.

Thankyou

import Tkinter
from Tkinter import *

def Test():
    global widgetEntry
    strVal = widgetEntry.get()
    print str(strVal)


root = Tk()                                                 # opens a
new window
textFrame = Frame(root)

widgetLabel = Label(textFrame)
widgetLabel.config(text = 'Enter text')
widgetLabel.pack(side = LEFT)
widgetLabel.pack(expand = YES, fill = BOTH)

widgetEntry = Entry(textFrame).pack(side = LEFT)
textFrame.pack()
Button(root, text = 'Submit', command=Test).pack(side=LEFT)

root.mainloop()

[toc] | [next] | [standalone]


#8588

FromPeter Otten <__peter__@web.de>
Date2011-06-29 23:35 +0200
Message-ID<mailman.514.1309383320.1164.python-list@python.org>
In reply to#8577
Robert Upton wrote:

> I am in the process of generating a simple GUI that wants to read a
> string and print it to the terminal after engaging a button.  I am
> running into a problem where Python says it does not understand the
> get() attribute for Entry.  

Please don't paraphrase Python's error messages. Cut-and-paste the traceback 
instead. This should give something like

$ python tmp_tk.py
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 1413, in __call__
    return self.func(*args)
  File "tmp_tk.py", line 6, in Test
    strVal = widgetEntry.get()
AttributeError: 'NoneType' object has no attribute 'get'

So the value of widgetEntry is None. How could that be?

> widgetEntry = Entry(textFrame).pack(side = LEFT)

The pack() method returns None; if you need a reference to the Entry widget 
you have to split that line

widgetEntry = Entry(textFrame)
widgetEntry.pack(side=LEFT)

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web