Python Forum
Removing an object from a graphic window
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Removing an object from a graphic window
#1
Good day, I'm attempting to help with an assignment. The school uses TechSmart. I was able to help with a couple of things, but this has us both stumped. The assignment is to show mouse action when hovering over an object. This part is okay. Here's the scenario.
Crow displayed at rest.
Move the cursor over the crow
Mallet is displayed and crow squawks
Remove cursor focus from the crow and it is displayed at rest.
This all works.

But, what doesn't work is removing the displayed mallet when focus is removed from the squawking crow.

I learned some C decades ago, but I'm a Python newbie and not much help with this. I've tried some things in the ELSE, but nothing is working to remove the mallet. Any direction is appreciated.
Thank you,
Jim

This is the current code:
import tsapp
window = tsapp.GraphicsWindow()

#### ---- SPRITE SETUP ---- ####

camp = tsapp.Sprite("Campgrounds.jpg", 0, 0)
crow = tsapp.Sprite("Crow.png", 400, 200)
crow.scale = 1.20
mallet = tsapp.Sprite("Mallet.png", 350, 50)
mallet.scale = 0.75

#### ---- SCENE CREATION ---- ####

window.add_object(camp)
window.add_object(crow)

while window.is_running:
    mouse_x, mouse_y = tsapp.get_mouse_position()
    if crow.is_colliding_point(mouse_x, mouse_y):
        crow.image = "CrowStartled.png"
        window.add_object(mallet)
    else:
        crow.image = "Crow.png"


    window.finish_frame()
Gribouillis write Jan-19-2025, 08:12 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
Is there a window.remove_object()?
Reply


Forum Jump:

User Panel Messages

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