Liam Pieri
Liam Pieri

Reputation: 643

Simple Tkinter program is not responding

So I am following the tutorial Intro to Tkinter and while copying the source code it did not work when I ran the program. I read over my syntax and searched the comments on the video, stack overflow, and I could not find a solution.

import Tkinter
import turtle
import sys

def main():

root = Tkinter.Tk()

cv = Tkinter.Canvas(root, width = 600, height= 600)

cv.pack(side = Tkinter.LEFT)

root.title("Draw")

t = turtle.RawTurtle(cv)

screen = t.getscreen()

screen.setworldcoordinates(0,0,600,600)

frame = Tkinter.Frame(root)
frame.pack(side = Tkinter.RIGHT, fill = Tkinter.BOTH)

def quithandler():
    print 'Goodbye'
    sys.exit(0)

quitbutton = Tkinter.Button(frame, text='Quit', command = quithandler)
quitbutton.pack()


if __name__ == "__main__":
    main()

Also I am running python 2.7 on windows. In this program the quit button does not show up, and the canvas does not respond instantly as I run it. What is causing it to do this every time?

Thank you for any help.

Upvotes: 0

Views: 623

Answers (1)

falsetru
falsetru

Reputation: 369474

Indent correctly. + You missed root.mainloop() call.

import Tkinter
import turtle
import sys

def main():
    root = Tkinter.Tk()
    cv = Tkinter.Canvas(root, width = 600, height= 600)
    cv.pack(side = Tkinter.LEFT)
    root.title("Draw")
    t = turtle.RawTurtle(cv)
    screen = t.getscreen()
    screen.setworldcoordinates(0,0,600,600)
    frame = Tkinter.Frame(root)
    frame.pack(side = Tkinter.RIGHT, fill = Tkinter.BOTH)
    quitbutton = Tkinter.Button(frame, text='Quit', command = quithandler)
    quitbutton.pack()
    root.mainloop()

def quithandler():
    print 'Goodbye'
    sys.exit(0)



if __name__ == "__main__":
    main()

Upvotes: 2

Related Questions