Toplevel windows and Tkinter

Jp Calderone exarkun at intarweb.us
Tue Mar 11 21:21:04 EST 2003


On Wed, Mar 12, 2003 at 02:05:35AM +0000, Oldleatheryhag97 wrote:
> Hello, 
> 
> I am new to Python and ran into problems while working on creating a messaging
> program. The problem is this: I would like Tkinter to create a new window for
> each incoming chat. However, if the recipient is already chatting with the
> message sender, the message will simply be sent to the window that is already
> open (In other words, a window is open for each user that the client chats
> with, like MSN Messenger, or AIM.)
> 
> I am seeking help in the creation of a function that would take the message and
> screenname of a sender, and then display a window. The primary problem is that
> I do not know how to give each of these windows a specific ID, or other
> distinguishing characteristic, that would allow me to send data to the specific
> window, based on the sender. Am I overlooking the obvious?
> 

  class MessageDispatch:
    def __init__(self):
      self.windows = {}

    def message(self, fromWhom, message):
        if not self.windows.has_key(fromWhom):
            self.windows[fromWhom] = ChatWindow(fromWhom)
        self.windows[fromWhom].receiveMessage(message)

  for example.  "fromWhom" needs to be unique, of course.  This might mean
using the IM's concept of a "UID" rather than their actual "screen name".

  Jp

-- 
#!/bin/bash
( LIST=(~/.sigs/*.sig)
  cat ${LIST[$(($RANDOM % ${#LIST[*]}))]}
  echo -- $'\n' `uptime | sed -e 's/.*m//'` ) > ~/.signature
-- 
 up 8 days, 17:59, 5 users, load average: 0.25, 0.19, 0.15





More information about the Python-list mailing list