Q:

Python tkinter moving object in def that as been created in another def

I am creating flappy bird style game. And my problem is that i cant move tubes that has been created on another def.
My code is
from tkinter import *
from random import randint
window = Tk()
c = Canvas(window, width=800, height=800, bg='steelblue')
tube11 = randint(600, 650)
tube12 = randint(400, 700)
def createtubes():
    tube1 = c.create_rectangle(800, 800, tube11, tube12, fill='green')
    tube2 = c.create_rectangle(800, 0, tube11, 200, fill='green')   
def automovement():
    if True:
        c.move(tube1, -3.5, 0)
        c.move(tube2, -3.5, 0)
    window.update_idletasks()
    window.after(10, automovement)
window.after(60, createtubes)
window.after(10, automovement)
c.pack()
window.mainloop()

A:

Try creating a class
from tkinter import *
from random import randint
window = Tk()
c = Canvas(window, width=800, height=800, bg='steelblue')
tube11 = randint(600, 650)
tube12 = randint(400, 700)
class Tubes:
    def __init__(self):
        self.createtubes()
    def createtubes(self):
        self.tube1 = c.create_rectangle(800, 800, tube11, tube12, fill='green')
        self.tube2 = c.create_rectangle(800, 0, tube11, 200, fill='green')   
    def automovement(self):
        if True:
            c.move(self.tube1, -3.5, 0)
            c.move(self.tube2, -3.5, 0)
        window.update_idletasks()
        window.after(10, self.automovement)
tube = Tubes()
window.after(10, tube.automovement)
c.pack()
window.mainloop()

