Set string in 'A' python script from 'B' python script
Question: I have two scripts:

A.py (is TK window)

    
    
    def function():
        string = StringVar()
        string.set("Hello I'm A.py")
    

From B.py I wish change string that appear in Tk window.

    
    
    def changestring():
        string.set("Hello I'm B.py")
    

Obviously don't work! How I can change string from another python script?


Answer: Variables have scopes. You cannot access variables which are in the scope of
one function from another function.

There has to be some common point in the code which "knows" about A and about
B. That code should pass the variables from one to the other.

Based on this comment:

> A.py is the graphic and B is the core with a infinite loop that listen the
> USB interrupt

I would say that you need two objects implementing the two functionalities,
let's call them "graphic" and "usb". One of them has to "know" about the
other. Either "graphic" should observe "usb", or "usb" should update
"graphic".

For example:

    
    
    # possibly in A.py:
    
    class Graphic(object):
        def __init__(self):
            self.string = StringVar()
    
        def function(self):
            self.string.set("Hello I'm A.py")
    
    
    # possibly in B.py:
    
    class USB(object):
        def __init__(self, graphic):
            self.graphic = graphic
    
        def changestring(self):
            self.graphic.string.set("Hello I'm B.py")
    
    
    # somewhere:
    
    from A import Graphic
    from B import USB
    
    def main():
        graphic = Graphic()
        usb = USB(graphic)
        #...
        usb.changestring()
    

