Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Turtle canvas background
#1
Is there a way to set a custom image as my turtle background on python
Reply
#2
(Oct-05-2019, 05:07 PM)joshp2709 Wrote: Is there a way to set a custom image as my turtle background on python

Hi!

I read your post and as I'm a very visual person, I tried but haven't managed it yet.

I have managed to use a custom image as a background image on my Cmder:

[Image: wonderful-cmder1.png]

https://python-forum.io/Thread-colouring...0#pid92380

or even on matplot:

[Image: butterfly.png]

https://python-forum.io/Thread-colouring...0#pid92210

I guess the solution is in here:

https://docs.python.org/3/library/turtle...rtle.bgpic

but I haven't managed it yet ...

All the best,



I FINALLY MANAGED IT!!!

I found the solution here:

https://stackoverflow.com/questions/4166...ound-image

So I used that program with my own images:
# turtle_bg_image_01.py
#
# It works!
#

import turtle
import time

screen = turtle.Screen()
screen.setup(600,400)
screen.bgpic('D:/programmation related/Butterfly_01.png')
screen.update()
time.sleep(2)
screen.bgpic('D:/programmation related/complex_quotations_02.PNG')
so it produces this output:

[Image: turtle-background-image-01.png]

and this one (the program runs showing one image and then after a few seconds (sleep() function), it shows the second image):

[Image: turtle-background-image-02.png]

As you can see in the program on line 11:

screen.bgpic('D:/programmation related/Butterfly_01.png')
and on line 14:

screen.bgpic('D:/programmation related/complex_quotations_02.PNG')
you have to use the full direction route of the images you want to use, that are in your computer.

All the best,



So now, you can use images as a background on your programs, like my simple draw a poligon program:

# turtle_bg_image_02.py
#
# It works!
#

import turtle
from turtle import *

speed(0)
screen = turtle.Screen()
screen.setup(400,400)
screen.bgpic('D:/programmation related/Butterfly_01.png')
screen.update()

nsides = input("Enter the number \
(bigger than 2) of sides of your \
desired poligon.\n")

ang1 = 360/int(nsides)
def poligon(sidelength=100):
    for i in range(int(nsides)):
        forward(sidelength)
        right(ang1)
poligon()
that running on my Python 3.7.4 Shell:
Output:
RESTART: C:/Users/User1/AppData/Local/Programs/Python/Python37/turtle_bg_image_02.py Enter the number (bigger than 2) of sides of your desired poligon. 6 >>>
produces the following output with turtle:

[Image: turtle-background-image-03.png]

where you can see that the hexagon has been drawn with the butterfly image as a background.

All the best,
newbieAuggie2019

"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  wn = turtle.screen() AttributeError: module 'turtle' has no attribute 'screen' Shadower 1 6,129 Feb-06-2019, 01:25 AM
Last Post: woooee
  Help! Turtle not working, even when we click the turtle demo in IDLE nothing happens. BertyBee 3 5,544 Jan-04-2019, 02:44 AM
Last Post: SheeppOSU

Forum Jump:

User Panel Messages

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