Hello all!
I have a problem on the Raspberry Pi where Geany will not show the Tkinter window when I am making a simple Python app with tkinter graphics.
I tried asking on Stack Exchange but no luck… I am sorry that I will just paste the question below, it’s the easiest way to be clear about it!
======
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? THANKS!
—— below is the code (from a learn-Python book)
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)
What happens if you run your script from the command line? I suspect it will just return the same as it does in Geany. Geany runs things exactly as if from the command line, so if your script doesn't run there it won't run in Geany.
The other IDE is a specialist Python thingy which may be doing something different, possibly helpful for beginners, but not so helpful when you actually want your script to run as a separate program independent of the IDE.
Cheers Lex
On 20 May 2018 at 11:25, Eric Stephan estephan@fastmail.net wrote:
Hello all!
I have a problem on the Raspberry Pi where Geany will not show the Tkinter window when I am making a simple Python app with tkinter graphics.
I tried asking on Stack Exchange but no luck… I am sorry that I will just paste the question below, it’s the easiest way to be clear about it!
======
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? THANKS!
—— below is the code (from a learn-Python book)
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)
Users mailing list Users@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/users
Hi -- thanks for that info!
-- I'm embarrassed to say that since I don't usually put longish scripts into the command line, I'm not sure how to get the many individual commands (with its odd bind commands etc) into just the command line. merely pasting it gives "SyntaxError: multiple statements found while compiling a single statement"
-- BUT anyway, I think the basic question would then be, if I wanted to write a python app that used TKinter windows like that, how would I do it so that Geany would show the results? TKinter is a quite commonly used component...
-- BTW, that script worked OK to show the TKinter output in both IDLE and Thonny IDEs
I'm guessing it's some not-too-complex little configuration or tweak somewhere...
thx Eric
On Sun, May 20, 2018, at 9:10 AM, Lex Trotman wrote:
What happens if you run your script from the command line? I suspect it will just return the same as it does in Geany. Geany runs things exactly as if from the command line, so if your script doesn't run there it won't run in Geany.
The other IDE is a specialist Python thingy which may be doing something different, possibly helpful for beginners, but not so helpful when you actually want your script to run as a separate program independent of the IDE.
Cheers Lex
On 20 May 2018 at 11:25, Eric Stephan estephan@fastmail.net wrote:
Hello all!
I have a problem on the Raspberry Pi where Geany will not show the Tkinter window when I am making a simple Python app with tkinter graphics.
I tried asking on Stack Exchange but no luck… I am sorry that I will just paste the question below, it’s the easiest way to be clear about it!
======
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? THANKS!
—— below is the code (from a learn-Python book)
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)
Users mailing list Users@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/users
Users mailing list Users@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/users
On 2018-05-19 09:06 PM, Eric Stephan wrote:
Hi -- thanks for that info!
-- I'm embarrassed to say that since I don't usually put longish scripts into the command line, I'm not sure how to get the many individual commands (with its odd bind commands etc) into just the command line. merely pasting it gives "SyntaxError: multiple statements found while compiling a single statement"
You save the code into a file with a .py extension, and run it with the command `python yourfile.py`. That will make Python execute all your code without having to re-type or paste it each time.
Regards, Matthew Brush
Try reading https://docs.python.org/3/library/tkinter.html#a-simple-hello-world-program and see what your script is missing to make it run as a complete program.
Cheers Lex
On 20 May 2018 at 14:06, Eric Stephan estephan@fastmail.net wrote:
Hi -- thanks for that info!
-- I'm embarrassed to say that since I don't usually put longish scripts into the command line, I'm not sure how to get the many individual commands (with its odd bind commands etc) into just the command line. merely pasting it gives "SyntaxError: multiple statements found while compiling a single statement"
-- BUT anyway, I think the basic question would then be, if I wanted to write a python app that used TKinter windows like that, how would I do it so that Geany would show the results? TKinter is a quite commonly used component...
-- BTW, that script worked OK to show the TKinter output in both IDLE and Thonny IDEs
I'm guessing it's some not-too-complex little configuration or tweak somewhere...
thx Eric
On Sun, May 20, 2018, at 9:10 AM, Lex Trotman wrote:
What happens if you run your script from the command line? I suspect it will just return the same as it does in Geany. Geany runs things exactly as if from the command line, so if your script doesn't run there it won't run in Geany.
The other IDE is a specialist Python thingy which may be doing something different, possibly helpful for beginners, but not so helpful when you actually want your script to run as a separate program independent of the IDE.
Cheers Lex
On 20 May 2018 at 11:25, Eric Stephan estephan@fastmail.net wrote:
Hello all!
I have a problem on the Raspberry Pi where Geany will not show the Tkinter window when I am making a simple Python app with tkinter graphics.
I tried asking on Stack Exchange but no luck… I am sorry that I will just paste the question below, it’s the easiest way to be clear about it!
======
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? THANKS!
—— below is the code (from a learn-Python book)
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)
Users mailing list Users@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/users
Users mailing list Users@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/users
Users mailing list Users@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/users
OK, that is totally useful! Thanks much. Going to get a sense of this broader set of classes etc. to set it up right.
thx! Eric
On May 20, 2018, at 11:18 AM, Lex Trotman elextr@gmail.com wrote:
Try reading https://docs.python.org/3/library/tkinter.html#a-simple-hello-world-program and see what your script is missing to make it run as a complete program.
Cheers Lex
On 20 May 2018 at 14:06, Eric Stephan estephan@fastmail.net wrote:
Hi -- thanks for that info!
-- I'm embarrassed to say that since I don't usually put longish scripts into the command line, I'm not sure how to get the many individual commands (with its odd bind commands etc) into just the command line. merely pasting it gives "SyntaxError: multiple statements found while compiling a single statement"
-- BUT anyway, I think the basic question would then be, if I wanted to write a python app that used TKinter windows like that, how would I do it so that Geany would show the results? TKinter is a quite commonly used component...
-- BTW, that script worked OK to show the TKinter output in both IDLE and Thonny IDEs
I'm guessing it's some not-too-complex little configuration or tweak somewhere...
thx Eric
On Sun, May 20, 2018, at 9:10 AM, Lex Trotman wrote:
What happens if you run your script from the command line? I suspect it will just return the same as it does in Geany. Geany runs things exactly as if from the command line, so if your script doesn't run there it won't run in Geany.
The other IDE is a specialist Python thingy which may be doing something different, possibly helpful for beginners, but not so helpful when you actually want your script to run as a separate program independent of the IDE.
Cheers Lex
On 20 May 2018 at 11:25, Eric Stephan estephan@fastmail.net wrote:
Hello all!
I have a problem on the Raspberry Pi where Geany will not show the Tkinter window when I am making a simple Python app with tkinter graphics.
I tried asking on Stack Exchange but no luck… I am sorry that I will just paste the question below, it’s the easiest way to be clear about it!
======
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? THANKS!
—— below is the code (from a learn-Python book)
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)
Users mailing list Users@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/users
Users mailing list Users@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/users
Users mailing list Users@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/users
Users mailing list Users@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/users
Le 20/05/2018 à 01:18, Lex Trotman a écrit :
Try reading https://docs.python.org/3/library/tkinter.html#a-simple-hello-world-program and see what your script is missing to make it run as a complete program.
FTR, from http://python-textbok.readthedocs.io/en/1.0/Introduction_to_GUI_Programming.... you can see the problem is that the program is missing a `window.mainloop()` call. This works inside a Python console because Python is running awaiting for input, but doesn't as a standalone application because Python just quits as it has done all processing. Launching the main loop obviously fixes the issue.
Regards, Colomban
On Fri, 25 May 2018 at 10:45, Colomban Wendling lists.ban@herbesfolles.org wrote:
Le 20/05/2018 à 01:18, Lex Trotman a écrit :
Try reading
https://docs.python.org/3/library/tkinter.html#a-simple-hello-world-program
and see what your script is missing to make it run as a complete program.
FTR, from
http://python-textbok.readthedocs.io/en/1.0/Introduction_to_GUI_Programming....
you can see the problem is that the program is missing a `window.mainloop()` call. This works inside a Python console because Python is running awaiting for input, but doesn't as a standalone
In fact both the other IDEs mentioned are Tk IDEs, so conveniently there is already a mainloop running.
application because Python just quits as it has done all processing. Launching the main loop obviously fixes the issue.
Regards, Colomban _______________________________________________ Users mailing list Users@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/users
Le 24/05/2018 à 21:56, Lex Trotman a écrit :
[…]
you can see the problem is that the program is missing a `window.mainloop()` call. This works inside a Python console because Python is running awaiting for input, but doesn't as a standalone
In fact both the other IDEs mentioned are Tk IDEs, so conveniently there is already a mainloop running.
As said it also works with the Python main loop, if you e.g. import the file as a module it behaves as the OP expected.
Aha!!! Big thank you to both of you guys… This is seriously an educational thread for me… Thank you! Eric
On May 25, 2018, at 8:00 AM, Colomban Wendling lists.ban@herbesfolles.org wrote:
Le 24/05/2018 à 21:56, Lex Trotman a écrit : […]
you can see the problem is that the program is missing a `window.mainloop()` call. This works inside a Python console because Python is running awaiting for input, but doesn't as a standalone
In fact both the other IDEs mentioned are Tk IDEs, so conveniently there is already a mainloop running.
As said it also works with the Python main loop, if you e.g. import the file as a module it behaves as the OP expected. _______________________________________________ Users mailing list Users@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/users
When you say those other two IDEs are Tk IDEs, does that mean that the IDE itself is built using Tk? or do you mean that they simply built a Tk loop into their app to make it convenient for programmers?
On May 25, 2018, at 8:12 AM, Eric Stephan estephan@fastmail.net wrote:
Aha!!! Big thank you to both of you guys… This is seriously an educational thread for me… Thank you! Eric
On May 25, 2018, at 8:00 AM, Colomban Wendling lists.ban@herbesfolles.org wrote:
Le 24/05/2018 à 21:56, Lex Trotman a écrit : […] you can see the problem is that the program is missing a `window.mainloop()` call. This works inside a Python console because Python is running awaiting for input, but doesn't as a standalone
In fact both the other IDEs mentioned are Tk IDEs, so conveniently there is already a mainloop running.
As said it also works with the Python main loop, if you e.g. import the file as a module it behaves as the OP expected. _______________________________________________ Users mailing list Users@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/users
Users mailing list Users@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/users
On Fri, 25 May 2018 at 11:15, Eric Stephan estephan@fastmail.net wrote:
When you say those other two IDEs are Tk IDEs, does that mean that the
IDE itself is built using Tk? or do you mean that they simply built a Tk loop into their app to make it convenient for programmers?
As I understand it both of those use the Python built-in tkinter GUI which uses tk.
On May 25, 2018, at 8:12 AM, Eric Stephan estephan@fastmail.net wrote:
Aha!!! Big thank you to both of you guys… This is seriously an
educational thread for me… Thank you!
Eric
On May 25, 2018, at 8:00 AM, Colomban Wendling <
lists.ban@herbesfolles.org> wrote:
Le 24/05/2018 à 21:56, Lex Trotman a écrit : […] you can see the problem is that the program is missing a `window.mainloop()` call. This works inside a Python console because Python is running awaiting for input, but doesn't as a standalone
In fact both the other IDEs mentioned are Tk IDEs, so conveniently
there is
already a mainloop running.
As said it also works with the Python main loop, if you e.g. import the file as a module it behaves as the OP expected. _______________________________________________ Users mailing list Users@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/users
Users mailing list Users@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/users
Users mailing list Users@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/users