“Python mengubah judul CMD” Kode Jawaban

Python mengubah judul CMD

>>> import ctypes
>>> ctypes.windll.kernel32.SetConsoleTitleA("My New Title")
Jittery Jaguar

Python mengubah judul CMD

import os
import ctypes
import msvcrt
import subprocess

from ctypes import wintypes

kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
user32 = ctypes.WinDLL('user32', use_last_error=True)

SW_MAXIMIZE = 3

kernel32.GetConsoleWindow.restype = wintypes.HWND
kernel32.GetLargestConsoleWindowSize.restype = wintypes._COORD
kernel32.GetLargestConsoleWindowSize.argtypes = (wintypes.HANDLE,)
user32.ShowWindow.argtypes = (wintypes.HWND, ctypes.c_int)

def maximize_console(lines=None):
    fd = os.open('CONOUT$', os.O_RDWR)
    try:
        hCon = msvcrt.get_osfhandle(fd)
        max_size = kernel32.GetLargestConsoleWindowSize(hCon)
        if max_size.X == 0 and max_size.Y == 0:
            raise ctypes.WinError(ctypes.get_last_error())
    finally:
        os.close(fd)
    cols = max_size.X
    hWnd = kernel32.GetConsoleWindow()
    if cols and hWnd:
        if lines is None:
            lines = max_size.Y
        else:
            lines = max(min(lines, 9999), max_size.Y)
        subprocess.check_call('mode.com con cols={} lines={}'.format(
                                cols, lines))
        user32.ShowWindow(hWnd, SW_MAXIMIZE)
Jittery Jaguar

Jawaban yang mirip dengan “Python mengubah judul CMD”

Pertanyaan yang mirip dengan “Python mengubah judul CMD”

Lebih banyak jawaban terkait untuk “Python mengubah judul CMD” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya