Problems with Tkinter Canvas
<p>I'm doing some simple tasks to prepare myself for python on University I am going to attend but I ran into a problem. 
When I ran my code for the first time, the tkinter window appeared and the image was drawn, but when I ran it for the second time, the tkinter window did not appear :( 
This is the code: </p>

<pre><code>import math, tkinter

canvas = tkinter.Canvas(width=300, height=300)
canvas.pack()
n = int(input('enter n: '))
x0, y0, r = 150, 150, 100
xx, yy = x0+r, y0
uhol = 360/n
for i in range(n):
    rad = uhol/180*math.pi
    x = x0 + r * math.cos(rad)
    y = y0 + r * math.sin(rad)
    canvas.create_line(x, y, xx, yy)
    xx, yy = x, y
    uhol += 360/n
</code></pre>

<p>Few hours before that, I wrote this code and it's working everytime I run it:</p>

<pre><code>import math, tkinter

canvas = tkinter.Canvas(width=300, height=300)
canvas.pack()
x0, y0, r = 150, 150, 100
xx, yy = x0+r, y0
for uhol in range(10, 361, 10):
    rad = uhol/180*math.pi
    x = x0 + r * math.cos(rad)
    y = y0 + r * math.sin(rad)
    canvas.create_line(x, y, xx, yy)
    xx, yy = x, y
</code></pre>

<p>I am using Python 3.5.2.</p>

<p>I presume that the second 'first' should be 'second'.  There are two other problems.</p>

<p>You did not say <em>how</em> you ran this either time.  Exact details can be important.</p>

<p>You did not create and pass to Canvas an instance of tkinter.Tk.  Instead, you relied on the default root mechanism.  I consider this unreliable and a bad idea.  Among other things, you cannot call methods on the hidden root.</p>

<p>I loaded your code into an IDLE editor, changed lines 2 &amp; 3 to</p>

<pre><code>root = tkinter.Tk()
canvas = tkinter.Canvas(root, width=300, height=300)
</code></pre>

<p>hit F5, and it ran.  I hit F5 again and it ran.  And again, and again.</p>

<p>To run from a command line or by double-clicking the file, you probably need to add this line at the end.</p>

<pre><code>root.mainloop()
</code></pre>

python canvas tkinter