I simply let the rope act as my hand would if they stand quietly the rope sits in my hand,
if they start throwing legs around the rope creates pressure equal to that they are putting out. I simply stand up straight and it's MUCH easier on my body then holding the leg with my hand.
When they realize it's not working I quietly go back to what I was doing previously.
This makes the right thing easy, the wrong thing hard.
There is no punishment per se and if I had the strength I'd hold with my hand but I don't. Also really handy for back legs to fix a kicking issue.
This won't work for a genuinely fear based issue but the way I read your post the horse is used to having it's legs handled.