`frame.set_canvas_background()` does not set the color
try:
import simplegui
except ImportError:
import SimpleGUICS2Pygame.simpleguics2pygame as simplegui
frame = simplegui.create_frame("My Frame", 100, 100)
frame.set_canvas_background("Red")
frame.start()
works on CodeSkulptor but does not work locally using PyGame.
I use the version 2.1.0 on Archlinux
Comments (7)
-
repo owner -
repo owner You need to define a drawing handler, else nothing is drawn. Something like that:
def draw(canvas): canvas.draw_text('Message', (50, 100), 32, 'White') frame.set_draw_handler(draw)
Tell me if that doesn’t work.
SimpleGUICS2Pygame is designed to have a behavior very similar than CodeSkulptor, but context are different, so there are some little differences, specially when a code is not really correct.
-
reporter Thank you Olivier, just creating an empty handler like this also solves the issue:
def draw(canvas): pass
Do you mean that the draw_handler function must be called every time I want to update the frame? So the behavior of Codeskulptor and also the alternative module
simplequi
is not correct?It seems like after the canvas background color is set, the canvas is updated manually.
Some background info: I am using the Interactive Python course in my class and the different behavior confuse some students.
-
reporter followup: The code was from the quiz2a of the first course:
https://www.coursera.org/learn/interactive-python-1/exam/QHZOz/quiz-2a/attempt => last question
-
repo owner “the draw_handler function must be called every time I want to update the frame?”
No. The idea is to define a drawing handler function (by example nameddraw
) and to associate it with your frame, like thisframe.set_draw_handler(draw)
. Then when the frame is started byframe.start()
the event loop automatically call the drawing handler multiple times by second. It is the same in CodeSkulptor and in standard Python with SimpleGUICS2Pygame.”I am using the Interactive Python course in my class”
Nice If you make some nice programs you can send me CodeSkulptor links to olivier.pirson.opi@gmail.com and I will add them to this list https://simpleguics2pygame.readthedocs.io/en/latest/_static/links/prog_links.html“different behavior confuse some students.”
I understand, but you need to accept that Python running in CodeSkulptor, so inside a navigator, and standard Python running in your computers have themselves different behaviors. I designed SimpleGUICS2Pygame to mimic the SimpleGUI behavior but there will always some differences.
Read this https://simpleguics2pygame.readthedocs.io/en/latest/Compatibility.html -
reporter No. The idea is to define a drawing handler function (by example named
draw
) and to associate it with your frame, like thisframe.set_draw_handler(draw)
. Then when the frame is started byframe.start()
the event loop automatically call the drawing handler multiple times by second. It is the same in CodeSkulptor and in standard Python with SimpleGUICS2Pygame.I see, so the code from the quiz2a in the Coursera course is not correct.
different behavior confuse some students.
I understand, but you need to accept that Python running in CodeSkulptor, so inside a navigator, and standard Python running in your computers have themselves different behaviors. I designed SimpleGUICS2Pygame to mimic the SimpleGUI behavior but there will always some differences.
Yeah, you are right. It is a tiny difference, but still the alternative library `simplequi` works without extra code. I will recommend
simplequi
then until further discrepancies occurhttps://simpleguics2pygame.readthedocs.io/en/latest/_static/links/prog_links.html
Such a long list for great procrastination
Thanks for your elaborate answer dear Olivier!
-
reporter - changed status to resolved
- Log in to comment
Hi Gökçe.
What is the reported error when you execute that?
Can you run the SimpleGUICS2Pygame_check.py script and show me the result?
Thank