multiple python UDP socket & UI
<p>I am very new to python and still in reading phase. I have two question here to discuss. I need to develop an python base user interface using <code>tkinter</code> which should run on Raspberry Pi2. On the background process I need to create multiple UDP socket server &amp; clients which is also python based. </p>

<p>I need to send data to a c++ application when the user press any button and select any value from combo box. Similarly I need to update the UI with the messages received from the C++ application. </p>

<p>I have create the basic UI and UDP socket in python which works as expected. Now I need to extend it so that I could send UI data to UDP Socket script and from there to C++ application.  </p>

<ol>
<li>How to instantiate multiple UDP socket? is there something similar to FD_SET, select() in python?</li>
<li>how to start both UI and background UDP socket script from a main.py script?</li>
<li>How to specify c# region like implementation like canvas as region one, combobox as region two, buttons as region three and label(labelframe) as region four and position then with different size.</li>
</ol>

<p>This is my python code:</p>

<pre><code>from tkinter import *
from tkinter import ttk

class MainWindow(Frame):
    def __init__(self):
        Frame.__init__(self)
        self.master.title("Test")
        self.master.minsize(330, 400)
        self.grid(sticky=E+W+N+S)

    modeFrame = Frame(self)
    actionFrame = Frame(self)
    msgframe = Frame(self)
    modeFrame.pack(side="top", fill="x")
    actionFrame.pack(side="top", fill="x")
    msgframe.pack(side="top", fill="x")

    # Mode Frame
    Label(modeFrame, text="Mode :", font="bold").pack(side="left")

    modeFrame.canvas1 = Canvas(modeFrame, height=25, width=25)
    modeFrame.setupled = modeFrame.canvas1.create_oval(5, 5, 20, 20, fill="green")
    modeFrame.canvas1.pack(side="left")
    Label(modeFrame, text="Setup Mode").pack(side="left")

    modeFrame.canvas2 = Canvas(modeFrame, height=25, width=25)
    modeFrame.setupled = modeFrame.canvas2.create_oval(5, 5, 20, 20, fill="black")
    modeFrame.canvas2.pack(side="left")
    Label(modeFrame, text="Run Mode").pack(side="left")

    # Action Frame
    Label(self, text="Select Coupon").pack(side="left")
    self.value_of_combo = 'X'
    self.combo("a,b,c")
    Button(self, text="Accept", command=acceptCallback).pack(side="left")
    Button(self, text="Reject", command=rejectCallback).pack(side="left")
    Button(self, text="EndSession", command=endSessionCallback).pack(fill="both", expand="yes", side="bottom")

    # Message Frame
    self.label0frame = LabelFrame(msgframe, text="ID")
    self.label0frame.pack(fill="both", expand="yes")
    Label(self.label0frame, text="Waiting for Client ...").pack(side="left")

    self.label1frame = LabelFrame(msgframe, text="Available Coupons")
    self.label1frame.pack(fill="both", expand="yes")
    Label(self.label1frame, text="Waiting for Client ...").pack(side="left")

    self.label2frame = LabelFrame(msgframe, text="Scanned Code")
    self.label2frame.pack(fill="both", expand="yes")
    Label(self.label2frame, text="Scanned Code ...").pack(side="left")

    self.label3frame = LabelFrame(msgframe, text="Status")
    self.label3frame.pack(fill="both", expand="yes")
    Label(self.label3frame, text="Status Message ...").pack(side="left")


def newselection(self, event):
    self.value_of_combo = self.comboBox.get()
    print(self.value_of_combo)

def combo(self,Values):
    self.box_value = StringVar()
    self.comboBox = ttk.Combobox(self, state="readonly", values=("a", "b", "c")) 
    self.comboBox.pack(side="left")
    self.comboBox.set("a")
    self.comboBox.bind("&lt;&lt;ComboboxSelected&gt;&gt;", self.newselection)

def acceptCallback():
    print("send Accept Message to C++")

def rejectCallback():
    print("send Reject Message to C++")

def endSessionCallback():
    print("send EndSession Message to C++")

if __name__ == "__main__":
    app = MainWindow()
    app.mainloop()
</code></pre>

<p>UDP socket code:</p>

<pre><code>import time
import struct
import socket
import sys

MYPORT = 51506
MYGROUP_4 = '225.0.0.1'

MYTTL = 1 # Increase to reach other networks

def UDPmain():
    udpApp = udpsocket()

class udpsocket():
    def __init__(self):
        print('UDP Socket started')
        group = MYGROUP_4
        self.receiver('225.0.0.1')

def sender(group):
    addrinfo = socket.getaddrinfo(group, None)[0]

    s = socket.socket(addrinfo[0], socket.SOCK_DGRAM)

    # Set Time-to-live (optional)
    ttl_bin = struct.pack('@i', MYTTL)
    if addrinfo[0] == socket.AF_INET: # IPv4
        s.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, ttl_bin)
    else:
        s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_HOPS, ttl_bin)

    while True:
        data = repr(time.time())
        s.sendto(data + '\0', (addrinfo[4][0], MYPORT))
        time.sleep(1)


def receiver(self,group):
    print('Receiver')
    # Look up multicast group address in name server and find out IP version
    addrinfo = socket.getaddrinfo(group, None)[0]

    # Create a socket
    s = socket.socket(addrinfo[0], socket.SOCK_DGRAM)

    # Allow multiple copies of this program on one machine
    # (not strictly needed)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

    # Bind it to the port
    s.bind(('', MYPORT))

    group_bin = socket.inet_pton(addrinfo[0], addrinfo[4][0])
    # Join group
    if addrinfo[0] == socket.AF_INET: # IPv4
        mreq = group_bin + struct.pack('=I', socket.INADDR_ANY)
        s.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
    else:
        mreq = group_bin + struct.pack('@I', 0)
        s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP, mreq)

    # Loop, printing any data we receive
    while True:
        data, sender = s.recvfrom(1500)
        while data[-1:] == '\0': data = data[:-1] # Strip trailing \0's
        print (str(sender) + '  ' + repr(data))
</code></pre>

<p>Kindly look the UI and the comments that I have mentioned</p>

<p><a href="https://i.stack.imgur.com/w18FS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w18FS.png" alt="enter image description here"></a></p>

<p>I appreciate people who goes through the entire question. Sorry for keeping it long</p>