I am developing a plugin in qgis. I have one interface (MMMM.py) with several buttons and one of them opens a new interface (ABC.py) where I introduce values. My objective is to read these values in the main interface (the first one). So I have a script to each interface but when I import the variables, I have several errors. I have troubles to import these variables.

second script named ABC.py

class ABC(QDialog, Ui_ABC):

    def __init__(self, iface):
       ...     

    def defineABC(self):

        x = self.input_x.text()
        y = self.input_y.text()
        return x, y

first (main) script named MMMM.py

class MMMM(QDialog, Ui_MMMM):

    def __init__(self, iface):
       ...

    def graph(self):
       import ABC
       x = ABC.ABC()
       xc = x.defineABC()

I tried some ways to import the values x and y to main interface but I have always errors. I am working in qgis.

What I am doing wrong?

有帮助吗?

解决方案

that would work:

from ABC import ABC
class MMMM(QDialog, Ui_MMMM):

  def __init__(self, iface):
    ...

  def graph(self):
    c = ABC()
    x, y = c.defineABC()

otherwise, you can set x and y in ABC (by doing self.x = ...) and then access them by c.x

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top