0

I am trying to switch to Geany IDE for coding Python on the Pi.

** Note, In an earlier question, I made the mistake of obscuring this question by combining it with another one... so this question never got noticed or answered... it needs its own question it seems. **

My problem: When I run my simple graphics tkinter python script (pasted below) in Geany, it "runs" ... BUT it simply shows the white-text-on-black script window proudly announcing that script completed... while the tkinter graphics window created by the script does not appear! When I do this in another IDE, Thonny, the graphics window appears. How do I get Geany to show this script's graphics window correctly?

from Tkinter import *

window = Tk()
window.title('Alien')
c = Canvas(window, height = 300, width=400)
c.pack()
body=c.create_oval(100,150,300,250,fill='green')
eye=c.create_oval(170,70,230,130,fill='white')
eyeball=c.create_oval(190,90,210,110,fill='black')
mouth=c.create_oval(150,220,250,240,fill='red')
neck=c.create_line(200,150,200,130)
hat=c.create_polygon(180,75,220,75,200,20,fill='blue')

def mouth_open():
    c.itemconfig(mouth,fill='black')
def mouth_close():
    c.itemconfig(mouth,fill='red')

def blink(event):
    c.itemconfig(eye, fill='green')
    c.itemconfig(eyeball, state=HIDDEN)
def unblink(event):
    c.itemconfig(eye, fill='white')
    c.itemconfig(eyeball, state=NORMAL)

words=c.create_text(200,280,text='I am an alien!')
def steal_hat():
    c.itemconfig(hat,state=HIDDEN)
    c.itemconfig(words, text='Give me my hat back!')

window.attributes('-topmost',1)

def burp(event):
    mouth_open()
    c.itemconfig(words,text="Burp!")
c.bind_all('<Button-1>', burp)

c.bind_all('<KeyPress-a>',blink)
c.bind_all('<KeyPress-z>',unblink)


def eye_control(event):
    key=event.keysym
    if key=='Up':
        c.move(eyeball,0,-1)
    if key=='Down':
        c.move(eyeball,0,1)
    if key=='Left':
        c.move(eyeball,-1,0)
    if key=='Right':
        c.move(eyeball,1,0)
c.bind_all('<Key>',eye_control)
  • Possible duplicate of Geany IDE use python 3?... and where is my Tkinter window? – Milliways May 12 '18 at 0:17
  • I added text above explaining that in that other question, this specific question never got an answer - because readers thought that fixing the "other" question in that post would fix this problem. It didn't... this question remains un-answered, but the other question isn't able to get an answer because readers think that the questions have the same root. Posting it here shows that it is a separate problem of its own. – estephan500 May 12 '18 at 2:13
0

I found the answer on a different site:

I had not put this line:

window.mainloop()

at the bottom of the script. This causes no problem when you are using an IDE that is built on Tk/Tkinter, because it has some kind of mainloop going by default. but if you want to run it in an IDE or setting other than that, you need that mainloop of course.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.