How to play GIF's using turtle module in Python? - python

I want the GIF to play in the turtle screen. But it is showing only the still image. Please fix this, Any help will be appreciated...
Here is my code:
import turtle
import os
# resources :
bgpic = r"C:\Users\intel\Desktop\xBDT7.gif"
win = turtle.Screen()
win.addshape(bgpic)
sh = turtle.Turtle()
sh.shape(bgpic)
# Shuting the window down :
turtle.mainloop()

From reading the turtle documentation, here, I don't see anything that says animated gifs can be played within turtle. You are free to read the documentation yourself, but It appears that although to use an image as a shape or background in turtle, it needs to be a .gif file, you cannot actually playback animated gifs in turtle.

Related

How can I find out which fonts are available in Turtle?

I'm working with python's turtle module and want to load different fonts. I've read that turtle uses tkinter's fonts but some of these fonts that should be available are in fact not. Does anyone know how I can add fonts or get a list of available ones? I would especially like to write arabic, hebrew fonts.
Try this to list fonts.
import tkinter as tk
r = tk.Tk()
print(list(tk.font.families()))
Turtle is based on tkinter, so you list the tkinter fonts.
To add a font, first download the font you want and install it on your system.
Then you can use this font in your code as shown in the example.
from turtle import Screen, Turtle
screen = Screen()
turtle = Turtle()
turtle.write("Pacifico Font", align='center', font=('Pacifico', 48))
screen.mainloop()
I hope it helps you about adding a new font.
Reference: How can I use custom local fonts in Python Turtle?
Also, you can check this out too.

Why can't I use a gif as a background with Turtle in Python?

I try to use a gif as a background for a game.
The games works fine but the background is stuck on the first frame of the gif.
I'm using Turtle library with Python.
Thank you :)
screen = turtle.Screen()
screen.setup(800, 600)
screen.bgpic('background.gif')
screen.update()
Sadly we cannot use gifs with Turtle.

Simple turtle commands to bring turtle graphics window to the foreground? (python 3 on OS X El Capitan)

I've been trying to work through some beginner python turtle graphics turtorials in python 3.7 on Mac OS X El Capitan.
One of the things that seems annoying is that the turtle graphics window is opening up underneath the other windows.
I don't know if there is something wrong with my configuration, or whether it is typical of turtle graphics, but it would be nice if there an easy way to bring the window to the foreground. I have searched and found out that turtle graphics is based on tkinter, and found a couple of post on bringing tkinter windows to thr foreground.
I was able to get the following code to work with IDLE, but it doesn't work when running the program from the terminal.
import turtle
# works in IDLE, but not in OS X terminal
root = turtle.getscreen()._root
root.attributes("-topmost", true)
turtle.forward(100)
turelt.left(120)
I have tried looking through the turtle graphics documentation, but I didn't find any commands to bring a window to the foreground, and I am not fond of the idea of having to do a deep read through tkinter documentation just to be able to run a beginner turtle graphics tutorial.
That being said, knowing the right commands to get a tkinter-able reference to the turtle window, and knowing the correct tkinter commands would seem like an acceptable workaround.
Are there any basic turtle commands to bring the window to the foreground, or is there a way to get a reference to the root tkinter window in order to bring it to ther foreground??
Thanks in advance for any help or suggestions!!
Sincerely,
Bryan Pierce

Turtle Graphic Window not working from VS Code

I am using Visual Studio Code as my IDE and I am a bit of a beginner with Python so I decided to try out the turtle library built into Python to learn some of the syntax. However, when I tried running just a simple script to see if it would work, the window flashed open for less than a second then closed. I have tried using different extensions and re-downloading the python extension for VS Code. This is my code I'm trying to run:
import turtle
geoff = turtle.Turtle()
geoff.forward(100)
Please help as I really can't figure out why the window won't stay open. Thanks!
The screen flashed on and then closed because when the application is done, Python exits and thus so does the screen. This has nothing to do with VS Code or the Python extension and simply how applications work.
Probably the easiest way to keep the window open is add the following line at the very end:
input("Press any key to exit ...")
That way Python won't exit until you press a key in the terminal.
The easiest solution is to add the following line in your V.S. Code:-
turtle.done()
This would prevent the window (Python Turtle Graphics) from closing after running the code:)
You can use exitonclick() to avoid the window from shutting down.
import turtle
window = turtle.Screen()
geoff = turtle.Turtle()
geoff.forward(100)
window.exitonclick()
This way, the graphics window will shut only after you click.
You can create a canvas into turtle like a blank space to draw on. Use this code just to import the module an hold on the graphic window open -Pen It will work with Visual Studio Code, Spyder or Python IDLE
import turtle
window = turtle.Screen()
geoff = turtle.Turtle()
t = turtle.Pen()
window.exitonclick()

Simple Python-Turlte Module

Quick Question.
How do I make Python Turtle Graphics screen pop-up directly on my screen and not in the background where I have to manually click on it to open it. I need to watch Python draw
To make your question Quick you need to post some code.
import turtle
myTurtle = turtle.Turtle()
myTurtle.circle(50)
turtle.getscreen()._root.mainloop()
starts on foreground for me (tried to run from komodo edit and command line on Ubuntu 64)

Categories

Resources