Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Conditional assignment ?
#11
It's ok I found it ! I just created 2 different targets just for different font and ask to draw one or the other depending on StimuliType column.

target = visual.TextStim(w, text="", color="white", height=sizeC, font="Courier New", pos=[0,yFirstThird])
target2 = visual.TextStim(w, text="", color="white", height=sizeC, font="BACS2sans", pos=[0,yFirstThird])
...
for i in range(len(d)):
...
    target.text = d.iloc[i,0]
    target2.text = d.iloc[i,0]
    for n in range(nCyWord):
        if d.iloc[i,3]=="PL":
            target2.draw()
            w.flip()
        else:
            target.draw()
            w.flip()
Still some problems with the code but I'll tell you if I'm stuck. You really help me there with the row thing, thanks.
Reply
#12
OK, this makes sense, I see now what you are doing.

Not tested but this should work:
for idx, row in d.iterrows():
    target = visual.TextStim(w, text=row['ortho'], color="white", height=sizeC, font="Courier New", pos=[0,yFirstThird])
    if row['StimuliType'] == 'PL':
        target.font = 'BACS2sans'
    target.draw()
    w.flip() # don't know what w is, I guess - some parent widget
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#13
I didn't do the actual code, I just have to modify it to fit my thesis experiment.

When I was assigning "target" in the for boucle there was an error because of some other stuff in the code, so I had to assign it before and fit it in the boucle (because I didn't wanted to modify too much of the code). But I hadn't wrote it that way, I didn't know that you could write it like this !

And w was my visual window :)

Have a good evening !
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020