Medical image segmentation plays a crucial role in medical image analysis but remains challenging due to complex anatomical structures and ambiguous tissue boundaries. While existing approaches have limitations in effectively exploiting feature maps through joint spatial and frequency-domain representations, we proposes a novel medical image segmentation framework based on spatial and frequency attention mechanisms, namely SFANet, to enhance segmentation accuracy and robustness. We innovatively proposes a convolutional multi-head self-attention module (CMSA), a multi-scale hybrid convolution module module (MSHCB), a frequency-enhanced channel attention module (FECA) and a dynamic grouped convolutional spatial attention module (DGCSA). Specifically, the CMSA module enhances global feature dependency modeling while maintaining computational efficiency through convolutional operations. The FECA module further improves detail sensitivity by fusing multi-frequency features across different scales. The DGCSA module combines dynamic grouped convolution with spatial attention mechanisms to enhance feature extraction, while enabling cross-scale feature fusion through adaptive convolution kernel weight adjustment. To enhance multi-scale feature extraction, we designed a multi-scale hybrid convolutional block (MSHCB) that adaptively processes features across different spatial dimensions. We conducte experiments on seven different modality datasets, and experimental results demonstrate that the proposed framework achieves significant performance improvements in multiple medical image segmentation tasks, exhibiting stronger segmentation capabilities and higher robustness than traditional methods.