I am using Tkinter to build a very simple trouchscreen-based experiment on the raspberry pie. I want to display a stimulus on the screen, constantly (so the list line of my code is win.mainloop(). At every click/touch of the stimulus, the stimulus should change position. I generate the stimulus positions with basic trigonometry by doing:
distance = 0.2
angle_range = list(range(0, 360, 45))
xc = (math.sin(angle_range[0] * 0.0174) * distance) + 0.5
yc = (math.cos(angle_range[0] * 0.0174) * distance) + 0.5
I then use xc and yc to position the stimulus on the screen (in this case it will be treated as a button by tkinter):
photo = PhotoImage(file="FaceStimulus.png")
Stimulus = Button(win, command=changePosition)
Stimulus.config(image=photo)
Stimulus.place(relx=xc, rely=yc)
And finally the function associated with the button
def changePosition():
print("Stimulus pressed")
angle_range = random.shuffle(angle_range)
In the function changePosition I ask for a shuffle of the positions list, which doesn't actually happen. The stimulus keeps always its initial position.
I am probably missing some very basic logic of python programming, sorry if this is a trivial question. I looked a bit online before writing here and I find some methods, but every time I try to implement them I run in the same logical error: how can I define over and over a variable from a function?