[Tkinter-discuss] entry+value assignment using function
Michael O'Donnell
michael.odonnell at uam.es
Sun Oct 31 10:06:06 CET 2010
Hi Alex,
Note the following line:
self.newlab=Entry(root,state=DISABLED).grid(column=4,row=9)
What is assigned to self.newlab is the result of the call to the grid function,
which is 'None'.
What you need to do is:
self.newlab=Entry(root,state=DISABLED)
self.newlab.grid(column=4,row=9)
...and then your code should work. See demo code below:
#=========================
from Tkinter import *
tk = Tk()
class tmp:
def __init__(self, root):
self.newlab=Entry(root,state=DISABLED)
self.newlab.grid(column=4,row=9)
self.PopSize=IntVar()
self.PopSize.set(7)
def pop2pop(self,event):
newpop=IntVar()
newpop.set(self.PopSize.get())
self.newlab['textvariable']=newpop
t=tmp(tk)
t.pop2pop(1)
tk.mainloop()
#+++++++++++++++++++++
On Sun, Oct 31, 2010 at 7:57 AM, Alex Ter-Sarkissov
<sigma.z.1980 at gmail.com> wrote:
> hi, here's my situation:
>
> I create an Entry outside of a certai function:
>
> self.newlab=Entry(root,state=DISABLED).grid(column=4,row=9)
>
> the function acquires a value (from another Entry) and puts this value into
> the Entry created in the command above. The way I do it is
>
> def pop2pop(self,event):
>
> newpop=IntVar()
> newpop.set(self.PopSize.get())
> #newpop=self.PopSize.get()
>
> self.newlab['textvariable']=newpop
>
>
> and it doens't work. Suprisingly, when I create the Entry within this
> function (e.g.
>
> self.newlab=Entry(root,textvariable=newpop).grid(column=4,row=9)
>
> it works.
>
> More over, the assignment of the value to newpop as
> (newpop=self.PopSize.get()) doesn't work either, so I have to use
> newpop.set(self.PopSize.get()) instead.
>
> what am I doing wrong?
>
> cheers,
>
> Alex
>
>
>
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>
>
More information about the Tkinter-discuss
mailing list