我编写了一些 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。除非有更好的方法来解决您的问题?