Is there a way to set a titlebar icon for the turtle module? I want to have something like this:
I want to put a titlebar icon and I don't know how.
Is there a way to set a titlebar icon for the turtle module? I want to have something like this:
I want to put a titlebar icon and I don't know how.
turtle is based on tkinter. Delving to the source code of turtle will reveal that in order to reach the underlying tkinter bases you need:
import turtle
root = turtle.Screen()._root
And now this root is actually a tkinter's Tk object which has the iconbitmap method:
root.iconbitmap("path_to.ico")
This seems to work:
import turtle
import tkinter
turtle.title('Hello Tux')
img = tkinter.Image("photo", file="/usr/share/pixmaps/tuxpaint.png")
turtle._Screen._root.iconphoto(True, img)
You have to call some function to force the creation of the root tkinter window, the most obvious is setting the title. Then you can access standard tkinter functions to set the icon.