2016-06-07 54 views
0

我试图获取冗余检查按钮的状态,以查看是否应该运行test.py脚本。当它现在起作用时,一旦点击了一个按钮,run.py就会关闭并运行testSomething函数。每当我尝试使用.get()或类似的东西来获取状态时,它会抛出模块对象没有属性错误。任何想法我做错了什么?另外,将if语句放在run.py文件或test.py文件中会更好吗?提前致谢。 Tool.py的尝试获取Checkbutton状态时,“模块”对象没有属性错误


相关线路

类ToolGui(帧): DEF create_widgets(个体): self.redundancyChecked = IntVar()

self.redundancyCheckbutton = Checkbutton(rightframe, onvalue=1, offvalue=0, text="Run Script?", variable=self.redundancyChecked) 

    self.redundancyCheckbutton.pack(side=TOP, pady=(5,0)) 

相关行run.py

class Threading(threading.Thread): DEF runC(个体,瓦里斯):

####if checkbutton is checked, run this...could go here 

    test.trySomething(workDir) 

的test.py

import os 
import sys 
import subprocess 


def trySomething(dir): 
    import Tool 
    ###or If statement could go here, not sure which would be better 
    Tool.redundancyCheckbutton.config(state=DISABLED) 
+0

请显示实际的错误 - 它告诉你哪个模块和哪个属性。作为一个经验法则,你应该从字面上理解错误信息,并假设它说的是实话。 –

回答

0

redundancyCheckbutton相关线路属于一类的一些实例的一个实例。我不知道什么课,因为你没有显示足够的代码。

很可能造成问题的原因(我假设,因为你没有显示实际的错误消息)线路是这样的:

import Tool 
Tool.redundancyCheckbutton.config(...) 

在此背景下,Tool是一个模块。该模块没有redundancyCheckbutton属性,就像错误消息告诉你的一样。同样,属性属于对象,而不是模块

最有可能在Tool的某个地方定义一个类。既然你没有说,为了这个答案的目的,我会说它被命名为GUI。因此,您有一个模块Tool,类别为GUI。这个类定义了一个属性self.redundancyCheckbutton

创建该检查按钮的唯一方法是创建该类的一个实例。因此,地方在你的代码,你必须做这样的事情:

​​

因此,要访问redundancyCheckbutton必须使用gui.redundancyCheckbutton,因为它是一个对象,它是由一个类定义的,它是在一个属性工具模块。

+0

这是正确的。工具。PY包含类和函数: ToolGui(帧): 高清create_widgets(个体经营): self.redundancyChecked = IntVar()...等与checkbutton 所以我怎么会得到redundancyChecked值?做一个它的实例? – burghermeister

+0

@burghermeister:你不需要做它的另一个实例。对于存在的检查按钮,您必须已经创建了一个实例。你只需要保持对该实例的引用。 –

相关问题