If I understand your question correctly, you're gonna want to use some form of event system. Treat entering text and receiving messages as events.
http://en.wikipedia.org/wiki/Event_(computing)
Event system in Python
Since something like this is a real-time program, your program is going to be running in a loop. Throughout the loop, events are put onto a queue, and at the beginning of each loop they are handled in the order they were triggered.
Since you're working with networking, maybe a dash of threading would be useful. Due to the Global Interpreter Lock, Python can't really use multithreading for performance boosts, but it's still useful for doing I/O in the back. This way, while your chat client (to use your example) is trying to get the message the other person has sent, the rest of the program doesn't freeze. This is especially beneficial for slow internet connections.