Write a Python program to get the height and width of the console window.

Write a Python program to get the height and width of the console window.

1
2
3
4
5
6
7
8
def terminal_size():
    import fcntl, termios, struct
    th, tw, hp, wp = struct.unpack('HHHH',
        fcntl.ioctl(0, termios.TIOCGWINSZ,
        struct.pack('HHHH', 0, 0, 0, 0)))
    return tw, th

print('Number of columns and Rows: ',terminal_size())

Final output

Leave a Comment