Turtle doesn't show window in full format in Linux Fedora

When I run the following test program in IDLE, I see for one second only a little small window in the top-left corner. I am working in Linux Fedora 38. Perhaps I have to write or install something more? Thanks in advance.
My code:

import turtle
my_turtle = turtle.Turtle()
my_turtle.forward(20)
1 Like

Welcome to the Python community, @gastverh!

Does it help if you add this line after the import statement?

scr = turtle.Screen()

Thanks for the quick reply and the fine welcome!
I have try it, but with the same result.
Do I have to do more with the variable scr?

import turtle
scr = turtle.Screen()
my_turtle = turtle.Turtle()
my_turtle.forward(20)

On Windows, when run in IDLE with 3.12, I get a large window (1000x1000?) with, as expected, a short line pointing right. I have no idea why you do not. Try running that code in a file directly with python in a command-line terminal. Also run the turtle demo with python -m turtle.

Your original code works on my MacBook Air with the Ventura OS, both with and without the suggested call to turtle.Screen(). It produces a large window as it does on @tjreedy’s Windows system. Unfortunately, my suggestion was just a guess that I couldn’t test adequately, since my OS is different from yours. We may need help from someone here who has Linux Fedora on their computer.

I have try it in a terminal and the result is the same one, but it stay running. As you can see, I still running IDLE 3.11.5:
[gastonv@localhost Python_The_Bible]$ dnf list installed | grep idle
python3-idle.x86_64 3.11.5-1.fc38 @updates
On this moment in Fedora I don not have an update, so I have to wait …
In the top of the screen I see a Tk-button, and there I can terminate the program and then I receive some remarks:

[gastonv@localhost Python_The_Bible]$ python -m turtle main.py
Traceback (most recent call last):
File “”, line 198, in _run_module_as_main
File “”, line 88, in _run_code
File “/usr/lib64/python3.11/turtle.py”, line 4156, in demo2()
File “/usr/lib64/python3.11/turtle.py”, line 4086, in demo2 lt(15)
File “”, line 5, in lt
Terminator

Is it possible that the window opens, and then closes immediately after the turtle has completed all its tasks? What happens if you keep it busy for perhaps a minute, for example as follows?:

import turtle
my_turtle = turtle.Turtle()
for line_len in range(4, 100, 4):
    my_turtle.fd(line_len)
    my_turtle.right(90)

It’s not really a solution, but might provide some insight into the nature of the problem.

Thanks for the reply, but the result is the same one.
With this example the program also ends immediately.
It have read it in a book for the first time and I tried to run it of course, just for learning.

It may be a problem specific to Fedora.

Have you had any previous problem using Tk on your system? You could try this as a test:

from tkinter import *
window=Tk()
window.title('Tk Example')
window.geometry("360x240")
btn=Button(window, text="An Example Button", fg='red')
btn.place(x=100, y=100)
window.mainloop()

It runs on my MacBook with no trouble.

Thank you for this reply.
With Tk and tkinter I have no problems, I could see your window with the title and the button very clear.
Because, with Tk, I have made a full wine cellar management program with all facilities.
Thus, I could run your program faultless also with no any trouble.
I have run it from terminal from a laptop and a screen.
Perhaps turtle only can run in Windows, I don’t know.

Perhaps the best strategy from here, then, would be to perform some searches for discussions about problems other programmers may have encountered with using turtle graphics with Python on Fedora systems. In the meantime, it may still turn out that someone on this forum who uses turtle graphics on a Fedora system has resolved this manner of issue. To attract such attention, you might consider editing the title of this discussion to include the term “Linux Fedora”. :wink:

If you do solve this problem, we would be interested in learning how you did it.

Does this work on your system?:

import tkinter
import turtle
win = tkinter.Tk()
canv = tkinter.Canvas(master = win, width = 200, height = 200)
canv.grid(row = 0, column = 0)
my_turtle = turtle.RawTurtle(canv)
for line_len in range(4, 100, 4):
    my_turtle.fd(line_len)
    my_turtle.rt(90)
win.mainloop()

It works on my MacBook Air.

EDIT:

The strategy here is to attempt a workaround that separates the instantiation of the Turtle from the creation of the window in which the Turtle operates.

With your having reported that tkinter works on your system, we create a tkinter.Tk() window. Then we associate a turtle.RawTurtle with a tkinter.Canvas on that window in hopes that it will circumvent the problem on your system with performing turtle graphics.

Many thanks for the reply, and I am happy to write that the program works in my Linux Fedora. I can run it either from IDLE or from the terminal.
The window is made with tkinter, the drawing is made with turtle in that window.
From now I can use this for more exercises.
Many thanks to all for the good communication.

1 Like

That’s great! We have been happy to help.

Here’s an image capture from the successful workaround:

Since explicitly creating a Tk window and then associating a RawTurtle with it via an explicitly created Canvas succeeded, after having relied on the Turtle instantiation to create the window had failed, it appears to me that there’s a bug in how your turtle.Turtle installation interacts with your computer’s operating system. It would be interesting to know if anyone else with Linux Fedora has encountered the same problem, and whether they resolved it.

We hope you continue to enjoy this forum, and we look forward to your future posts!.

Because the problem for my Linix Fedora is solved with your tkinter turtle code, I tried to do the same one in order to show an image:

import tkinter
import turtle
from turtle import RawTurtle, TurtleScreen
win = tkinter.Tk()
canv = tkinter.Canvas(master = win, width = 400, height = 200)
canv.grid(row = 0, column = 0)
my_turtle = TurtleScreen(canv)
my_turtle.bgpic('worldmap.gif')
win.mainloop()

The result:
Schermafdruk van 2023-10-11 15-38-19

What is the actual width and height of the 'worldmap.gif' image in pixels?

The width and height of 'worldmap.gif' is 903 x 452 pixels.

Here’s the documention regarding the background picture:

turtle.bgpic(*picname=None*)

It does not discuss what happens if the image dimensions are larger than the dimensions of the tkinter.Canvas. Perhaps the image gets truncated in that case.

EDIT:

If you change the fifth line of your most recent code to the following, in order to match the size of the image, does it produce a better result?:

canv = tkinter.Canvas(master = win, width = 903, height = 452)

The following workaround might form a basis for a satisfactory solution:

import tkinter
import turtle
root = tkinter.Tk()
root.title("Blue Marble Earth Image")
canv = tkinter.Canvas(master = root, width = 440, height = 220)
canv.grid(row = 0, column = 0)
scr = turtle.TurtleScreen(canv)
# Public domain image from Wikipedia page at https://en.wikipedia.org/wiki/The_Blue_Marble
scr.bgpic('BlueMarble_monthlies_animation.gif')
root.mainloop()

The code produces this Tk window:

Tk Screenshot Blue Marble

The Blue Marble public domain image was downloaded from the following Wikipedia page:

The reason of my questions is, I am reading Python The Bible, enclosing 3 books. The second book has a chapter: ‘Where is the Space Station Project’. Because I am interesting this, I was interested to learn: ‘Step 2; I find the ISS Location’. Now I can show the position of ISS on the worlmap.
Many thanks for the previous answers with hints. Later I will change it to the bigger worldmap.
My code:

import json
import turtle
import time
import tkinter
import urllib
import urllib.request
from tkinter import *
from turtle import RawTurtle, TurtleScreen
url = 'http://api.open-notify.org/iss-now.json'
response = urllib.request.urlopen(url)
result = json.loads(response.read())
print(result, '\n')
location = result['iss_position']
lat = location['latitude']
lon = location['longitude']
print('latitude: ', lat)
print('longitude:', lon)
win = tkinter.Tk()
width_value = win.winfo_screenwidth()
height_value = win.winfo_screenheight()
print(width_value)
print(height_value)
canv = tkinter.Canvas(master = win, width = 720, height = 360)
canv.grid(row = 0, column = 0)
screen = TurtleScreen(canv)
screen.bgpic('worldmap.gif')
lat = 29.5502 # test latitude
lon = -95.097 # test logitude
my_turtle = turtle.RawTurtle(screen)
my_turtle.goto(lon * 2.55, lat * 2.4) # draw corrections
my_turtle.fillcolor('red')
my_turtle.begin_fill()
my_turtle.circle(2)
my_turtle.end_fill()
win.mainloop()

The picture with the red ISS at the left:

1 Like