A Dangling Tk Entry

W. eWatson notvalid2 at sbcglobal.net
Mon Mar 9 06:20:09 CET 2009


r wrote:
> On Mar 8, 9:34 pm, "W. eWatson" <notval... at sbcglobal.net> wrote:
> 
>> Radiboutton(master, textvariable = ...
>> Radiobutton(msster, textvariable = ...
>> Checkbox(master, text=...
>> entry = Entry(master, width=10, ...
>> entry.insert(0,self.slowdown)    # testing a default methodology
>> Label( master, text="Max...
>> Entry(master, width=10, textvar...
>> ...
>> return entry
>>
>> First, what is the meaning of entry=Entry(...? That is, other than create an
>> Entry, why that particular position, and why not with say Checkbox?
> 
> It sounds like you don't understands some fundamentals of Tkinter
> programming. You only need to create a reference(instance) to a tk
> widget if you plan to access it later. Widgets like labels (in some
> cases) will never change, so creating an instance is just furturing
> your capal tunnel avancment. :). Checkbuttons and Radiobuttons use
> Variables to query thr widget so they also do not need to be
> "instanced"
> 
> Something else that you need to understand, You must explicitly  pack
> (), place(), or grid() a widget instance if you wish to call that
> instance later or you will get an error.
> 
> #-- this no work --#
> entry = Entry(master).pack() #cannot call entry.method()
> 
> #-- this works --#
> entry = Entry(master)
> entry.pack()
> 
>> Further,
>> SetDlg has used ShowDlg by calling dialog=ShowDlg(( self.master, set_a...
>> dialog is then used to get at the parameters set by the user. I thought I'd
>> give ShowDlg an attribute by using entry.insert(0,self.slowdown inserting it
>>   before return. Upon return from ShowDlg, which was invoked by, dialog =
>> ShowDlg( self.master, set_a ..., I thought I'd grab slowdown with x=
>> dialog.slowdown. The program didn't get that far, so, second, I'd like to
>> know why it died on the insert statement? That line, produced 'NoneType'
>> object has no attribute 'insert' , and entry and its type are None and >type
>> 'NoneType'> What has gone wrong?
> 
> I would suspect a geometry manager issue here but you really should
> post all the code for this dialog.
> 
Guilty as charged, somewhat. I'm modifying someone else's code to provide 
new features, and have modest understanding of how Tk works. However, the 
reason for making them an instance is not unreasonable at all. This should 
work.

I really don't think the geometry mgr has anything to do with it. If there's 
an early miscue here on my part, it's about using insert. My understanding 
is that insert will allow me put something into the entry area shown in the 
widget on the screen. That is if, I put up: Enter Data Here: ______, the 
_____ represents the entry widget created. What I'm trying to do is 
initialeze it with, say, 1234.

You didn't answer my question why entry is necessary at all. The original 
author thought it was necessary to return entry. I'll give you a peek at a 
segment of the code I'm working with here:

class Enter_Data_Dialog(tkSimpleDialog.Dialog):

     def __init__(self, parent, sdict):
         self.sdict = sdict
         tkSimpleDialog.Dialog.__init__(self, parent)

     def body(self,master):
         self.title("Set a Number Entry Dialog")

         Label( master, text="Number ").grid(row=0, sticky=W)
         self.anumberVar = StringVar()
         entry = Entry(master, width=10,
  			textvariable=self.anumberVar).grid(row=0, column=1)
         self.anumberVar.set( "%d" % self.sdict["anumber"] )

         return entry

This code works. What I'm trying to do is to eliminate the unnecessary use 
of control variables. As it, stands the calling program sets up the default 
value for anumber and returns whatever new value enters.

-- 
                                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/>




More information about the Python-list mailing list