Turtle canvas background - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Turtle canvas background (/thread-21584.html) |
Turtle canvas background - joshp2709 - Oct-05-2019 Is there a way to set a custom image as my turtle background on python RE: Turtle canvas background - newbieAuggie2019 - Oct-05-2019 (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: https://python-forum.io/Thread-colouring-strings?pid=92380#pid92380 or even on matplot: https://python-forum.io/Thread-colouring-strings?pid=92210#pid92210 I guess the solution is in here: https://docs.python.org/3/library/turtle.html?highlight=turtle#turtle.bgpic but I haven't managed it yet ... All the best, I FINALLY MANAGED IT!!! I found the solution here: https://stackoverflow.com/questions/41664941/python-turtle-change-displayed-background-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: and this one (the program runs showing one image and then after a few seconds (sleep() function), it shows the second image): 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: produces the following output with turtle:where you can see that the hexagon has been drawn with the butterfly image as a background. All the best, |