It is relatively simple to find the right method, just upload the code (applicable to Linux).
import fcntl
import sys
import termios
import struct
def get_terminal_size():
"""
获取Linux控制台窗口尺寸
:return: (行数,列数)
"""
t = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, "1234")
return struct.unpack('HH', t)
Call the function directly to get the return value: print(get_terminal_size())