Jan-16-2018, 09:31 AM
Hello,
I've been trying to write a reaction time task with stimuli appearing on screen using the tkinter module.
While this function does work:
Does anybody have an idea?
(P.S.: I'm new using python, I'm sorry for my messy lines of code)
I've been trying to write a reaction time task with stimuli appearing on screen using the tkinter module.
While this function does work:
def show_stim(stim, side, verpos, police): x = screensize[0]/2 + side y = screensize[1]/2 + verpos PTcanvas.create_text(x, y, text=stim.value, fill=stim.color, font=police) PrimTask = Tk() #Fenetre de la tâche principale PTcanvas = Canvas(PrimTask, background='black', height = screensize[1], width = screensize[0]) PTcanvas.pack() #fonts definition italic = font.Font(PrimTask, family='Times', size=50, slant='italic') underli = font.Font(PrimTask, family='Times', size=50, underline=1) polices=[italic, underli] #stimulus instanciation and display x = stimulus('lettre') show_stim(x, 150, 150, italic) PrimTask.mainloop() PrimTask.quit()Using show_stim() in a function does not work:
def Trial(): pair = ['lettre', 'chiffre'] vert = [-150, 150] verposD = vert[randint(0,1)] verposG = vert[randint(0,1)] Stype = pair[randint(0,1)] StimD = stimulus(Stype) if Stype == 'lettre': StimG = stimulus('chiffre') else: StimG = stimulus('lettre') SDpolice = polices[randint(0,1)] SGpolice = polices[randint(0,1)] show_stim(StimD, 150, verposD, SDpolice) show_stim(StimG, -150, verposG, SGpolice)
Error:Traceback (most recent call last):
bricole.py", line 71, in <module>
Trial()
bricole.py", line 49, in Trial
show_stim(StimD, 150, verposD, SDpolice)
bricole.py", line 55, in show_stim
PTcanvas.create_text(x, y, text=stim.value, fill=stim.color, font=police)
File "C:\Users\Vincent\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 2498, in create_text
return self._create('text', args, kw)
File "C:\Users\Vincent\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 2474, in _create
*(args + self._options(cnf, kw))))
_tkinter.TclError: invalid command name ".!canvas"
I don't know why but the error goes back in the _create method, and I can't see where it tries to to call this ".!canvas" command.Does anybody have an idea?
(P.S.: I'm new using python, I'm sorry for my messy lines of code)