Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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 1920×1080, 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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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}')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading