Unable to run annoying_message.py using Visual Studio Code
Hi all,
I'm a programmer with quite some years of experience, but completely new with Python. I'm currently trying to run annoying_message.py from PyGaze to get familiarized with it, but it's not working properly. I'm running this using Windows 10, Visual Studio Code and Python 3.6 32bits with Pygaze 0.7 (obtained using pip). I think the error is when I try to use draw_text() because I have another example where I load an image instead of text in the Display() and it works fine! This is the code, and it's pretty much what the py file contains:
# your message
MESSAGE = "HELLO WORLD"
# import stuff
import random
from pygaze.defaults import *
from pygaze import libtime
from pygaze.libscreen import Display, Screen
from pygaze.libinput import Keyboard
# start timing
libtime.expstart()
# objects
disp = Display()
scr = Screen()
kb = Keyboard(keylist=['space'],timeout=1)
# run annoying message
while kb.get_key()[0] == None:
# colour
col = (random.randint(0,255), random.randint(0,255), random.randint(0,255))
# position
pos = (random.randint(0,DISPSIZE[0]), random.randint(0,DISPSIZE[1]))
# text
scr.draw_text(text=MESSAGE, colour=col, pos=pos, fontsize=84)
# display
disp.fill(scr)
disp.show()
# reset screen
scr.clear()
# stop the madness
disp.close()
I haven't been able to identify the issue, because as soon as Display() is called, I only see the PyGame community message in the terminal, and a grey screen covering the whole screen, which I understand is the actual Display object that I called, but it does not allow me to go back to Visual Studio Code and keep debugging. I'm not able to go through each line of code because the grey screen seems to put everything else "frozen" while runs.
I would appreciate the help, thanks!
Comments
Hi,
As far as I know, Pygaze is not yet Python 3 compatible. So, you probably have to retry with Python 2.7.
Good luck,
Eduard
@eduard PyGaze IS Python 3 compatible!
As for the actual problem here, it's hard to debug without an error message! There are a few things you could do to get around the persistent grey screen issue:
1) Run scripts using Python directly, not within your code editor. You can create a batch file to call
"C:\Python37\python.exe" "my_script_name.py"
(example; you'd have to use the path to python.exe on your own machine), ideally followed bypause
so that the command prompt stays visible for you to read the error message.2) Switch to the "psychopy" backend; their screens are often less persistent than the PyGame one. (Meaning you should be able to Alt+Tab to your editor to check the error message.)
Good luck!