Home > Back-end >  I have made a bit of code that gets your resolution in Windows, how do I make it print it in an f st
I have made a bit of code that gets your resolution in Windows, how do I make it print it in an f st

Time:07-15

I have made a bit of Python code that gets your resolution in Windows, how do I make it print it in an f string?

# 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='')

Its output is 1920x1080, but I need it to be like because it's going to be among other code

print(f'''Resolution: {screen_resolution}''')
User: {getuser()}

as I am trying to remake neofetch. Unless there is a better way of getting your resolution?

CodePudding user response:

Change screensize definition to:

screenwidth, screenheight = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)

then skip all the rest of the code and replace it with:

print(f'Resolution: {screenwidth}x{screenheight}')

CodePudding user response:

You could add you results to a string if you want like this:

import ctypes
# get screen resolution
user32 = ctypes.windll.user32
screensize = user32.GetSystemMetrics(0), 'x', user32.GetSystemMetrics(1)
full_res = ''
# 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:
    full_res  = str(item)
print(f"Resolution: {full_res}")

or a better way imo

import ctypes
user32 = ctypes.windll.user32
screensize = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)
print(str(screensize[0])   'x'   str(screensize[1]))
  • Related