473,473 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Access from one class to methode of other class

VK
Hi, all!

In my programm i have to insert a variable from class 2 to class 1 and I
get error NameError: global name 'd' is not defined. How do I get access
to d.entry.insert() method of class 1

class 1:
self.entry = Entry(self.entryframe)
self.entry.pack()

self.button = Button(command = self.callclass2window)

def callclass2window
c = 2()
class 2:
def ins(self)
d.entry.insert(variable)
d = 1()
Jul 19 '05 #1
11 1335
I don't know if your're actually calling the classes '1' and '2', but
that's a really bad idea!
class 2:
def ins(self)
d.entry.insert(variable)


This is probably where you're getting the NameError. d is not defined,
so calling d.entry will generate an error.

Reidar

Jul 19 '05 #2
VK
> I don't know if your're actually calling the classes '1' and '2', but
that's a really bad idea!

class 2:
def ins(self)
d.entry.insert(variable)



This is probably where you're getting the NameError. d is not defined,
so calling d.entry will generate an error.

Reidar


What is d = 1() in my example then? And how do I solve this problem?
ч
Jul 19 '05 #3
VK wrote:
I don't know if your're actually calling the classes '1' and '2', but
that's a really bad idea!

class 2:
def ins(self)
d.entry.insert(variable)
This is probably where you're getting the NameError. d is not defined,
so calling d.entry will generate an error.


What is d = 1() in my example then?


a global variable.
And how do I solve this problem?


passing d to the instance of 2 *could* be a solution.

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Jul 19 '05 #4
VK wrote:
Hi, all!

In my programm i have to insert a variable from class 2 to class 1 and I
get error NameError: global name 'd' is not defined.
Looking at your code snippet, I think you have a lot of other errors
before.

class 1:
self.entry = Entry(self.entryframe)

NameError : self is not defined

etc...

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Jul 19 '05 #5
On Thu, 26 May 2005 14:33:45 +0200, VK <"myname"@example.invalid>
declaimed the following in comp.lang.python:
Hi, all!

In my programm i have to insert a variable from class 2 to class 1 and I
get error NameError: global name 'd' is not defined. How do I get access
to d.entry.insert() method of class 1

class 1: <shudder> Does Python even allow numeric class names?

REAL code, stripped to the minimum that duplicates your problem,
is always better than pseudo-code...
self.entry = Entry(self.entryframe)
self.entry.pack()

self.button = Button(command = self.callclass2window)

def callclass2window
c = 2()
class 2:
def ins(self) NO : ???
d.entry.insert(variable)
d = 1()
What, might I ask, does .insert() /do/ for an Entry() object?

As far as I can tell, "class 1" is creating some GUI button.
Pressing that button invokes your callclass2window(), which creates a
new "class 2" instance, and then throws it away.

Give us code that we can /run/ and we might be able to give you
an answer...
-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Jul 19 '05 #6
VK
> VK wrote:
Hi, all!

In my programm i have to insert a variable from class 2 to class 1 and I
get error NameError: global name 'd' is not defined.

Looking at your code snippet, I think you have a lot of other errors
before.

class 1:
self.entry = Entry(self.entryframe)


NameError : self is not defined

etc...


That is not real code, only dummy describing the problem
Jul 19 '05 #7
VK
> On Thu, 26 May 2005 14:33:45 +0200, VK <"myname"@example.invalid>
declaimed the following in comp.lang.python:

Hi, all!

In my programm i have to insert a variable from class 2 to class 1 and I
get error NameError: global name 'd' is not defined. How do I get access
to d.entry.insert() method of class 1

class 1:
<shudder> Does Python even allow numeric class names?


:-D don't know

REAL code, stripped to the minimum that duplicates your problem,
is always better than pseudo-code...
I thought that is it...

self.entry = Entry(self.entryframe)
self.entry.pack()

self.button = Button(command = self.callclass2window)

def callclass2window
c = 2()
class 2:
def ins(self)
NO : ???

d.entry.insert(variable)
d = 1()

What, might I ask, does .insert() /do/ for an Entry() object?


That insert text into entry object.

As far as I can tell, "class 1" is creating some GUI button.
Pressing that button invokes your callclass2window(), which creates a
new "class 2" instance, and then throws it away.
Yes, exactly

Give us code that we can /run/ and we might be able to give you
an answer...


I try:

from Tkinter import *

class First:
def __init__(self):
self.root = Tk() # create window contents as children to
root..
self.entryframe = Frame(self.root)
self.entryframe.pack(fill=BOTH,expand=1)

self.entry = Entry(self.entryframe)
self.entry.pack(side=TOP,expand=1,fill=BOTH)
self.entry.focus()
self.entry.bind('<Return>',(lambda event: self.fetch())) #
on enter key

self.button =
Button(self.entryframe,text="Call",command=self.ge tvar)
self.button.pack(side=LEFT,expand=YES,fill=BOTH)

self.root.mainloop()

def fetch(self):
print 'Input => "%s"' % self.entry.get() # get text form entry

def getvar(self,event=0):
c=Second(self,self.root)

class Second:
def __init__(self,parent,s="thing"):
self.root = Tk()
self.ent = Entry(self.root)
self.ent.pack()
self.btn = Button(self.root,text='Fetch',command=self.fetch)
self.btn.pack(side=RIGHT)
def fetch(self):
text = self.ent.get() # get text form entry in this window
d.entry.insert(0, text)# must insert in other window

d = First() #First window
Jul 19 '05 #8
On 5/26/05, VK <my****@example.invalid> wrote:
That is not real code, only dummy describing the problem


We realise that. The problem is that there are problems in your dummy
in addition to the real problems, and we can't tell them apart.

--
Cheers,
Simon B,
si***@brunningonline.net,
http://www.brunningonline.net/simon/blog/
Jul 19 '05 #9
VK wrote:
On Thu, 26 May 2005 14:33:45 +0200, VK <"myname"@example.invalid>
declaimed the following in comp.lang.python:

Hi, all!

In my programm i have to insert a variable from class 2 to class 1
and I get error NameError: global name 'd' is not defined. How do I
get access to d.entry.insert() method of class 1

from Tkinter import *

class First:
def __init__(self):
self.root = Tk() # create window contents as children to
root..
self.entryframe = Frame(self.root)
self.entryframe.pack(fill=BOTH,expand=1)

self.entry = Entry(self.entryframe)
self.entry.pack(side=TOP,expand=1,fill=BOTH)
self.entry.focus()
self.entry.bind('<Return>',(lambda event: self.fetch())) #
on enter key

self.button =
Button(self.entryframe,text="Call",command=self.ge tvar)
self.button.pack(side=LEFT,expand=YES,fill=BOTH)

self.root.mainloop()

def fetch(self):
print 'Input => "%s"' % self.entry.get() # get text form entry

def getvar(self,event=0):
c=Second(self,self.root)

class Second:
def __init__(self,parent,s="thing"):
self.root = Tk()
self.ent = Entry(self.root)
self.ent.pack()
self.btn = Button(self.root,text='Fetch',command=self.fetch)
self.btn.pack(side=RIGHT)
def fetch(self):
text = self.ent.get() # get text form entry in this window
d.entry.insert(0, text)# must insert in other window

d = First() #First window


The problem is that First.__init__() never returns so the instance of First is never bound to d.
Take the line
self.root.mainloop()
out of First.__init__() and and the line
d.root.mainloop()

at the end of the program and it will work as you expect.

Kent
Jul 19 '05 #10
VK
Kent Johnson wrote:
VK wrote:
On Thu, 26 May 2005 14:33:45 +0200, VK <"myname"@example.invalid>
declaimed the following in comp.lang.python:
Hi, all!

In my programm i have to insert a variable from class 2 to class 1
and I get error NameError: global name 'd' is not defined. How do I
get access to d.entry.insert() method of class 1



from Tkinter import *

class First:
def __init__(self):
self.root = Tk() # create window contents as children to
root..
self.entryframe = Frame(self.root)
self.entryframe.pack(fill=BOTH,expand=1)

self.entry = Entry(self.entryframe)
self.entry.pack(side=TOP,expand=1,fill=BOTH)
self.entry.focus()
self.entry.bind('<Return>',(lambda event: self.fetch())) #
on enter key

self.button =
Button(self.entryframe,text="Call",command=self.ge tvar)
self.button.pack(side=LEFT,expand=YES,fill=BOTH)

self.root.mainloop()

def fetch(self):
print 'Input => "%s"' % self.entry.get() # get text form
entry

def getvar(self,event=0):
c=Second(self,self.root)

class Second:
def __init__(self,parent,s="thing"):
self.root = Tk()
self.ent = Entry(self.root)
self.ent.pack()
self.btn = Button(self.root,text='Fetch',command=self.fetch)
self.btn.pack(side=RIGHT)
def fetch(self):
text = self.ent.get() # get text form entry in this window
d.entry.insert(0, text)# must insert in other window

d = First() #First window

The problem is that First.__init__() never returns so the instance of
First is never bound to d. Take the line
self.root.mainloop()
out of First.__init__() and and the line
d.root.mainloop()

at the end of the program and it will work as you expect.

Kent


O, God! It works! Thousend of thanks!

By the way, the second window appears not activ, is there an option to
make it activ on start?

Reg,VK
Jul 19 '05 #11
Dennis Lee Bieber <wl*****@ix.netcom.com> writes:
On Thu, 26 May 2005 14:33:45 +0200, VK <"myname"@example.invalid>
declaimed the following in comp.lang.python:
Hi, all!

In my programm i have to insert a variable from class 2 to class 1 and I
get error NameError: global name 'd' is not defined. How do I get access
to d.entry.insert() method of class 1

class 1:

<shudder> Does Python even allow numeric class names?


Fortunately, no:
class 1:

File "<stdin>", line 1
class 1:
^
SyntaxError: invalid syntax

--
--------------------------------------------------------------------
Aaron Bingham
Software Engineer
Cenix BioScience GmbH
--------------------------------------------------------------------

Jul 19 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: EMW | last post by:
Hi Is it possible to convert a MDB access database to a XML (sheet/something)? I'm very new with XML, thus I don't know all its possibilities. I'm writing a program for my PDA and since it is...
4
by: EMW | last post by:
Hi Is it possible to convert a MDB access database to a XML (sheet/something)? I'm very new with XML, thus I don't know all its possibilities. I'm writing a program for my PDA and since it is...
4
by: Miro | last post by:
Vb2003, im still learning vb.net but I do not understand my output from this logic. If someone can help me out here. Cor Ligthert, you I believe were on the right track of what Im trying to...
7
by: kenny.deneef | last post by:
Hey all We are working on a project and have alot of forms with textboxes on. Now we want to put some input validation keypress events on those textboxes. We got a parent class where we putted...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.