I'm trying to do a GUI with Tkinter (python 2.7) that finds what serial COM's are in use and then the user can choose one to communicate with, much like Arduino's IDE in "Tools -> Port". I have two main problems: 1º When I insert the COM ports in the drop down menu, no matter which label I choose, always returns the higher COM number one. I've got an idea why but still can't solve it. 2º I don't know how to save the chosen label and use it later.

```
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import re
from Tkinter import *
import tkMessageBox 
from serial import *
import serial

def find_ports(): #find all active COM's

    active_ports = []
    for number in range(10):
        try:
            verify = serial.Serial('COM'+str(number))
            active_ports.append((number, verify.portstr))
            verify.close()

        except serial.SerialException:
            pass
    return active_ports

def chooseCom(index): #choose COM by clicking on a label
    choosedPort = portMenu.entrycget(index, "label")
    print choosedPort
    pass

numPorts = find_ports()
root = Tk()

# -------------------------- Main Frames  --------------------------
toolbar = Frame(root)
data = Frame(root)

# -------------------------- Menu --------------------------
menu = Menu()
root.config(menu = menu)

subMenu = Menu(menu, tearoff = 0)
menu.add_cascade(label="Ports", menu = subMenu)

portMenu = Menu(subMenu, tearoff = 0)
for i,item in enumerate(numPorts):
    portMenu.add_command(label=str(item[-1]), command = lambda: chooseCom(i))   

serialPort = someVAr # someVar => Store the choosed label
baudRate = 9600
ser = Serial(serialPort , baudRate, timeout=0, writeTimeout=0) 

subMenu.add_cascade(label="Ports", menu = portMenu)

root.mainloop()

```

For the 1º problem, I think that is the 'i' variable that stays with a high number by the end of the 'for'. The following code works instead of the 'for' loop:

```
portMenu.add_command(label="COM1", command = lambda: chooseCom(0))
portMenu.add_command(label="COM2", command = lambda: chooseCom(1))

```

unfortunately it doesn't work for me because I'll run this in different computers and I can't garantee that the COM ports will be the same.

The second problem is that I want to save the chosen label in some variable (someVar) and use it later to configure my Serial connection in:

```
serialPort = someVAr # someVar => Store the choosed label
baudRate = 9600
ser = Serial(serialPort , baudRate, timeout=0, writeTimeout=0) 

```

Thank you.