[IronPython] Adding more than one entry to a TextBox WPF

Andrew Evans evans.d.andrew at gmail.com
Sun Jul 11 14:06:36 PDT 2010


Hello I am building a simple python app to further educate myself.

I am almost some what complete with this application. However I can not
think how to add more than one entry to a TextBox. So when I input the first
value it stays and then the second value third and so forth right now it
replaces the first value with the second etc etc

Here is my app code

#PYTHON#


import clr
clr.AddReference("PresentationFramework")
clr.AddReference("PresentationCore")

from System.IO import File
from System.Windows.Markup import XamlReader
from System.Windows import *

import socket
from threading import *
import cPickle

CMD_MSG = range(1)

class Chat(object):
    def __init__(self):
      mythread = Thread(target=self.server)
      mythread.start()
      stream = File.OpenRead("p2pChat.xaml")
      self.root = XamlReader.Load(stream)
      self.ip_address_input = self.root.FindName('ip_address')
      self.sendB = self.root.FindName('send')
      self.output = self.root.FindName('textbox')
      self.entry_input = self.root.FindName('entry')
      self.sendB.Click += self.sendit

    def server(self):
      self.port = 9000
      self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      self.s.bind((socket.gethostbyname(socket.gethostname()),
int(self.port)))
      #print socket.gethostbyname(socket.gethostname())
      while True:
        msg, addr = self.s.recvfrom(2024)
##        cmd, msg = ord(msg[0]),msg[1:]
##        if cmd == CMD_MSG:
        self.output.Text = str(msg) + "\n"

    def client(self, msg):
        self.port = 9000
        self.host = self.ip_address_input.Text
        self.se = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.se.sendto(str(self.host) + " : " + msg, (self.host,
int(self.port)))

    def sendit(self, s, e):
        self.client(str(self.entry_input.Text))
        self.output.Text = str(self.entry_input.Text + "\n")
        self.entry_input.Text = ""



myChat = Chat()


app = Application()
app.Run(myChat.root)

Thanks in advance :-)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ironpython.com/pipermail/users-ironpython.com/attachments/20100711/cd9c641b/attachment.htm>


More information about the Users mailing list