Get available all COM port to tkinter combo box in Python
<p>I have a <strong>tkinter GUI</strong> with a Combo box.</p>

<p>I want to get all available COM ports to combo box at starting GUI and I need to perform a function while changing combo box value.</p>

<p>I have <strong>pyserial</strong> and I'm using <strong>Python 2.7</strong>.</p>

<p>How can I do this?</p>

<p><strong>UPDATE</strong></p>

<p>This is the function for get COM ports..I want to bind this for  my GUI.And I need a combo box changing event.</p>

<pre><code>import sys
import glob
import serial


def serial_ports():


    ports = ['COM%s' % (i + 1) for i in range(256)]

    result = []
    for port in ports:
        try:
            s = serial.Serial(port)
            s.close()
            result.append(port)
        except (OSError, serial.SerialException):
            pass
    return result


if __name__ == '__main__':
    print(serial_ports())
</code></pre>

<p>I have added this configuration for get the ports in to combo box.</p>

<pre><code>self.comboComNum.configure(values=serial_ports())
</code></pre>

<p><strong><em>QUESTION</em></strong></p>

<p>How can I implement a more accurate and faster function for get COM ports?</p>

<p>How can I get combo box changing event?</p>