Python Forum
Moving with objects simultaneously
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Moving with objects simultaneously
#1
Hello,

I'm currently working on my project and stucked at this point:

I want to create a canvas, where different objects will move (a lot of game NPCs). But whilst they are moving, I want to be able to do a different things in canvas, like buying items for a game and so on. And the point I got stuck in makes me feel that the way how do I want to let canvas do different things simultaneously is quiet wrong.

class Class1:

    def __init__(self):
        self.canvas = tkinter.Canvas(width=500, height=500, bg="white")
        self.canvas.pack()
        number = x
        self.create_npc(number)
        ...

    def create_npc(self):
        for i in range(number):
            self.canvas.after(3000)
            self.npc = NPC(self)

    ...

class NPC:

    def __init__(self, class1):
        self.main = class1
        self.place_npc()
        self.move_npc()

    def place_npc(self):
        self.object_npc = self.main.canvas.create_image(some_x, some_y, image=self.main.cars['self.car_image_1']) #there is a dict with all car images

    def move_npc(self):
        while True:
            self.main.canvas.move(self.object, 10, 0)
So I want to let this object move, after it is created in 'def create_npc' as one of 'number' NPCs. But instead, it creates just one NPC, and actually my tkinter canvas never opens, because while True is still running. Can you help me please? Is there any way how could I say "donĀ“t care this method is running, just continue with executing next lines of program"?
Reply


Messages In This Thread
Moving with objects simultaneously - by kom2 - Apr-20-2019, 06:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to run same process simultaneously exploit123 1 2,437 Sep-19-2019, 10:08 AM
Last Post: Gribouillis
  Control 2 stepper motor simultaneously jihene 2 4,008 May-08-2019, 05:27 PM
Last Post: DeaD_EyE
  moving objects Francisco 4 2,618 Dec-09-2018, 07:54 PM
Last Post: woooee
  using subpocess for both reading and writing simultaneously dauriac 11 9,637 May-30-2018, 10:09 PM
Last Post: killerrex
  controlling multiple server simultaneously. caligola 3 3,595 May-11-2018, 05:44 PM
Last Post: wavic
  How to define two functions run simultaneously within a function? Alberto 4 4,016 Feb-06-2018, 10:08 PM
Last Post: Alberto
  Modifying / extracting multiple list items simultaneously using variable from range ehammarlund 4 3,678 Dec-06-2017, 08:15 PM
Last Post: ehammarlund

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020