我编写了一些代码可以在 Windows 中获取您的分辨率,如何让它以 f 字符串打印出来?

jus*_*ser 0 python windows

我编写了一些 Python 代码,可以在 Windows 中获取您的分辨率,如何让它以 f 字符串打印出来?

# libraries
import ctypes

# get screen resolution
user32 = ctypes.windll.user32
screensize = user32.GetSystemMetrics(0), 'x', user32.GetSystemMetrics(1)

# list to store resolution and the x that is between them
items = []

# add resolution to list
for item in screensize:
    resolution = (str(item))
    items.append(item)

# print resolution
for item in items:
    print(item, end='')
Run Code Online (Sandbox Code Playgroud)

它的输出是 1920x1080,但我需要它是这样的,因为它会在其他代码中

print(f'''Resolution: {screen_resolution}''')
User: {getuser()}
Run Code Online (Sandbox Code Playgroud)

因为我正在尝试重新制作 neofetch。除非有更好的方法来解决您的问题?

Sha*_*ger 5

将定义更改screensize为:

screenwidth, screenheight = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)
Run Code Online (Sandbox Code Playgroud)

然后跳过所有其余代码并将其替换为:

print(f'Resolution: {screenwidth}x{screenheight}')
Run Code Online (Sandbox Code Playgroud)