Skip to content Skip to sidebar Skip to footer

Python Tkinter Not Working In A .py File

My problem is that my python code is not working when I run it as a .py file. Here is the code: import tkinter tk=tkinter.Tk() canvas=tkinter.Canvas(tk, width=500, height=500) can

Solution 1:

You are missing the eventloop at the end:

import tkinter
tk=tkinter.Tk()
canvas=tkinter.Canvas(tk, width=500, height=500)
canvas.pack()

# Enter into eventloop <- this will keep# running your application, until you exit
tk.mainloop()

Only a personal recommendation: don't use tk as a variable name, use app or root or even win/window

Post a Comment for "Python Tkinter Not Working In A .py File"