从一个类访问到其他类的方法 [英] Access from one class to methode of other class

查看:65
本文介绍了从一个类访问到其他类的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!


在我的程序中,我必须将类2中的变量插入到类1中,并且我将获得错误NameError:全局名称d没有定义。我如何获得访问

到第1类的d.entry.insert()方法


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(变量)

d = 1()

解决方案

我不喜欢知道你的'实际上是在叫''1'还是'''',但是

这是一个非常糟糕的主意!

2级:
def ins(self)
d.entry.insert(变量)




这可能就在你的位置获取NameError。 d没有定义,

所以调用d.entry会产生错误。


Reidar


>我不知道你的'实际上是在叫1还是2,但是

这是一个非常糟糕的主意!

第2课:
def ins(self)
d.entry.insert(变量)




这可能是你得到NameError的地方。 d没有定义,所以调用d.entry会产生错误。




什么是那么在我的例子中d = 1()?我该如何解决这个问题呢?

??


VK写道:

我不知道你的'实际上是在叫''1'还是'''',但是这是一个非常糟糕的主意!

第2课:
def ins(self)
d.entry.insert(变量)

这可能是你得到的地方NameError。 d没有定义,所以调用d.entry会产生错误。



在我的例子中,d = 1()是什么?




a全局变量。

如何解决这个问题?




将d传递给实例2 *可能*是一个解决方案。


-

bruno desthuilliers

python -c" print''@' '.join([''。''。join([w [:: - 1] for p in p.split(''。'')])for

p in''o * *** @ xiludom.gro''。split(''''')])"


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()

解决方案

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


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


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(''@'')])"


这篇关于从一个类访问到其他类的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆