Can't run crontab without excecuting the programm once
<p>I wrote a <code>script.py</code> which should open a <code>Tkinter</code> window on a raspberry:</p>

<pre><code>from Tkinter import *
import turtle
import math
import time
import sys
import os

root = Tk()
root.config(cursor="none")
ccanvas = Canvas(root, width = 800, height = 480)
root.overrideredirect(1) 
turtle_screen = turtle.TurtleScreen(ccanvas)
ccanvas.pack()
turtle = turtle.RawTurtle(turtle_screen)
turtle.hideturtle()
mainloop()
</code></pre>

<p>I am able to run the script from the command line with:</p>

<pre><code>python /home/pi/script.py
</code></pre>

<p>When I tried to run it via <code>crontab</code> first the Display was not found. I fixed that with:</p>

<pre><code>DISPLAY=:0 python /home/pi/script.py
</code></pre>

<p>But now I get the following error: <code>_tkinter.TclError: couldn't connect to display ":0"</code> until I execute the <code>script.py</code> once manual in the cmd. Then the <code>crontab</code> is able to execute the <code>script.py</code> without that error. How can I fix that?</p>

<p>Finally solved my problem. Everything was fine, but i was using the <code>root crontab</code>. The <code>root crontab</code> was not able to find the display, before the display was not mentioned/used by another command. I transferred my <code>cronjobs</code> to the "normal" <code>crontab</code> and everything works fine. 
Another point is that commands, which need the display (for example Tkinter) do not work if you start them <code>@reboot</code>. You have to implement some sleep time (~30 seconds) in your script, so the display has time to become available.</p>

<pre><code>import time

time.sleep(30)

...
</code></pre>

python tkinter crontab raspberry-pi3