[Python] Changing a variable in another file, with a function in that file

Discussão em 'Python' iniciado por Stack, Maio 23, 2025.

  1. Stack

    Stack Membro Participativo

    I have two files. file1 and file2.

    file1:

    color = (0, 0, 0)
    class drawing:
    def changeColor(newColor):
    global color
    color = (newColor)
    def drawCircle(x, y, r, c=color)
    #circle draw function from pygame (not important)


    file2:

    from file1 import *
    circle = drawing()
    drawing.changeColor((255,255,255))
    drawing.drawCircle(0, 0, 5)


    and yet the circle still comes out black.

    I've tried putting a print(color) command after the changeColor function, and it returns (0, 0, 0) too.

    Assuming that my drawing function is correct, and my class definition is correct, is there anything else that I'm doing wrong?

    Continue reading...

Compartilhe esta Página