Can I extract the outline of a single closed segment?

Can I extract the outline/contour of each slice of closed segment and then draw a closed curve from it with code?

Yes, sure. You can retrieve the closed surface representation of the segment, get intersection by using VTK cut filter, sort the points using vtkContourTriangulator, then add the polygon points as curve control points. This code may help: https://github.com/Slicer/Slicer/pull/1075/files

I donnot know how to get intersection and create a closed curve from points after covert the segment to a polygon data with python(just learned python). Could you help me?
segmentationNode=getNode(‘Segmentation’)
segmentId = segmentationNode.GetSegmentation().GetNthSegmentID(0)
segmentPolyData=segmentationNode.GetClosedSurfaceRepresentation(segmentId)

Once you have the closed surface representation, use standard VTK filters, as they are used in the segmentation displayable manager (see relevant code in the pull request above). You can get learn about VTK by studying the VTK textbook and VTK examples website.