[Tutor] Trying to use tkinter in Pycharm EDU

Peter Otten __peter__ at web.de
Wed Feb 8 08:32:40 EST 2017


Lisa Hasler Waters wrote:

> Hello,
> 
> We have been able to get the turtle module in PycharmEDU by ending our
> code with turtle.done()
> 
> However, we cannot get the tkinter module to actually run in PycharmEDU.
> For example, when we input the following very simple code we get a line in
> the console that reads  "Process finished with exit code" and we can see
> that a canvas is trying to open but it never does:
> 
> from tkinter import *
> tk = Tk()
> canvas = Canvas(tk, width=500, height=500)
> canvas.pack()
> 
> OR this code:
> 
> from tkinter import *
> tk = Tk()
> btn = Button(tk, text="click me")
> btn.pack()

Try adding the line

  tk.mainloop()


Running an event loop is necessary for every tkinter program.
 
> Both of these worked fine in IDLE. 

As idle itself uses tkinter there's probably an odd interference between 
idle and your script causing it to share the editor's event loop so that it 
appears to work.

> But we really like the Pycharm EDU and
> want to continue using it.
> 
> We are working on Macs 10.11.6 with Pycharm EDU 3.0.1.
> 
> We are obviously missing something! Any advice would be appreciated!
> 
> Thanks so much!
> 
> Lisa
> 




More information about the Tutor mailing list