Pass variable in Python module
<p>I am working with image processing project with Python. I need a good GUI, so I have generated a GUI using <a href="https://sourceforge.net/projects/page/" rel="nofollow noreferrer">PAGE</a>.
Now I have three .py files:</p>

<ol>
<li>PAGE generated GUI class file.</li>
<li>PAGE generated GUI Support file.</li>
<li>My image processing file.</li>
</ol>

<p>PAGE generated GUI support file defines global veritable for storing GUI component values.</p>

<p>PAGE generated GUISupport.py:</p>

<pre><code>#! /usr/bin/env python
#
# Support module generated by PAGE version 4.8.6
# In conjunction with Tcl version 8.6
#    Nov 16, 2016 07:58:07 AM


import sys

try:
    from Tkinter import *
except ImportError:
    from tkinter import *

try:
    import ttk
    py3 = 0
except ImportError:
    import tkinter.ttk as ttk
    py3 = 1

global frm #this is the global variable
frm=None

def init(top, gui, *args, **kwargs):
    global w, top_level, root
    w = gui
    top_level = top
    root = top

def destroy_window():
    # Function which closes the window.
    global top_level
    top_level.destroy()
    top_level = None

if __name__ == '__main__':
    import GUI
    GUI.vp_start_gui()
</code></pre>

<p>PAGE generated GUI.py. I have added a show_frame() function separately. According to <a href="https://stackoverflow.com/questions/32342935/using-opencv-with-tkinter">this</a> information.</p>

<pre><code>#! /usr/bin/env python
#
# GUI module generated by PAGE version 4.8.6
# In conjunction with Tcl version 8.6
#    Nov 16, 2016 07:58:02 AM
import sys
import Tkinter as tk
import Image, ImageTk

try:
    from Tkinter import *
except ImportError:
    from tkinter import *

try:
    import ttk
    py3 = 0
except ImportError:
    import tkinter.ttk as ttk
    py3 = 1

import GUISupport

def vp_start_gui():
    '''Starting point when module is the main routine.'''
    global val, w, root
    root = Tk()
    top = MainForm (root)
    GUISupport.init(root, top)
    root.mainloop()

w = None
def create_MainForm(root, *args, **kwargs):
    '''Starting point when module is imported by another program.'''
    global w, w_win, rt
    rt = root
    w = Toplevel (root)
    top = MainForm (w)
    top.show_frame()
    GUISupport.init(w, top, *args, **kwargs)
    return (w, top)

def destroy_MainForm():
    global w
    w.destroy()
    w = None


class MainForm:
    def __init__(self, top=None):
        '''This class configures and populates the toplevel window.
           top is the toplevel containing window.'''
        self._bgcolor = '#d9d9d9'  # X11 color: 'gray85'
        self._fgcolor = '#000000'  # X11 color: 'black'
        self._compcolor = '#d9d9d9' # X11 color: 'gray85'
        self._ana1color = '#d9d9d9' # X11 color: 'gray85' 
        self._ana2color = '#d9d9d9' # X11 color: 'gray85' 


        top.geometry("850x500+318+153")
        top.title("MainForm")
        top.configure(background="#d9d9d9")


        self.lblFrame = Label(top)
        self.lblFrame.place(relx=0.01, rely=0.02, height=471, width=764)
        self.lblFrame.configure(background="#d9d9d9")
        self.lblFrame.configure(disabledforeground="#a3a3a3")
        self.lblFrame.configure(foreground="#000000")
        self.lblFrame.configure(text='''Label''')
        self.lblFrame.configure(width=764)

    def show_frame(self):
        img = Image.fromarray(GUISupport.frm)
        imgtk = ImageTk.PhotoImage(image=img)
        self.lblFrame.imgtk = imgtk
        self.lblFrame.configure(image=imgtk)
        self.lblFrame.after(10, show_frame) 


if __name__ == '__main__':
    create_MainForm(Tk())
</code></pre>

<p>This is my image processing code written using OpenCV</p>

<pre><code>import numpy as np
import cv2

import GUISupport as guis

cam=cv2.VideoCapture(0)

while 1:
    _,f=cam.read()
    cv2.imshow('frame',f)
    guis.frm=cv2.cvtColor(f, cv2.COLOR_BGR2RGBA) #this is the variable passed using GUISupport.py

    if cv2.waitKey(1) &amp; 0xFF == ord('q'):
        cv2.destroyAllWindows()
        cam.release()
        break
</code></pre>

<p>I have run this code. But, I got this error:</p>

<pre><code>File "C:\Users\user\Documents\Visual Studio 2013\Projects\testforCAmFeed\testforCAmFeed\GUI.py", line 74, in show_frame
    img = Image.fromarray(GUISupport.frm)
AttributeError: class Image has no attribute 'fromarray'
</code></pre>

<p>I need to pass my video and other variable to the GUI module and need to pass tkinter GUI controller data to image processing module.</p>

<p>How to do this?</p>