J.G.
I was having the same problem with my son (he just turned 4 Monday) until he found out that he really could push mommy too far. I gave him warnings, but he would still scream when it was time to go. One day I very quietly and calmly told him that if he didn't get his shoes and leave with me right then we would never come back (we were at McD). I think the quiet and calm really got through to him that I was serious, it was the tone. There have been a few times since that he's talked back a little, but I just get my purse and head toward the door and he's right there. Of course, I'd never leave him, but he's gotten the message that when we say it's time to go, it's time to go. Before we go somewhere, we usually have a discussion about leaving nicely when I say it's time. I have also put him in time out when we get home and discuss his behavior when he's acted ugly, but honestly we've only had to do that once or twice. Since we finally got the message to him without being frustrated, he's done great.
Good luck!