Python에서 모니터 해상도 얻기

Lakshay Kapoor 2021년7월12일
Python에서 모니터 해상도 얻기

많은 작업에는 Python에서 GUI를 개발하여 애플리케이션 및 운영 체제와 상호 작용합니다. 따라서 이러한 종류의 절차를 수행하기 위해 Python은 여러 패키지와 라이브러리를 제공합니다. GUI를 포함하는 작업 중 하나는 모니터의 해상도를 얻는 것입니다.

이 튜토리얼은 Python에서 모니터의 해상도를 얻는 방법에 대한 방법을 보여줍니다.

Python에서Tkinter라이브러리 사용

Tkinter패키지는 Python의 GUI 라이브러리입니다. 이 라이브러리는 GUI 애플리케이션 개발에 도움이되는 GUI 도구 키트를 제공하여 Python을 지원합니다. 이 라이브러리를 사용하여 Python은 다른 애플리케이션과 쉽게 상호 작용할 수 있습니다. 아래 예제 코드를 확인하십시오.

from tkinter import *

root = Tk()

monitor_height = root.winfo_screenheight()
monitor_width = root.winfo_screenwidth()

print("width x height = %d x %d (pixels)" % (monitor_width, monitor_height))
mainloop()

출력:

width x height = 1440 x 900 (pixels)

위 프로그램에서 먼저tkinter라이브러리를 가져옵니다. 그런 다음 다음 단계에서 기본적으로 응용 프로그램의 기본 응용 프로그램 창인root window을 만듭니다. 응용 프로그램에서 작업을 수행하기 전에이 창을 정의해야합니다.

그 후root.winfo_screenheight()root.winfo_screenwidth()메소드를 각각 사용하여 모니터의 크기를 얻습니다. 반환 된 값은pixels에 있습니다.

Lakshay Kapoor avatar Lakshay Kapoor avatar

Lakshay Kapoor is a final year B.Tech Computer Science student at Amity University Noida. He is familiar with programming languages and their real-world applications (Python/R/C++). Deeply interested in the area of Data Sciences and Machine Learning.

LinkedIn