使用 Tkinter Python 获取屏幕高度和宽度
Tkinter 是赋予 Python 程序 GUI 编程能力的库。作为 GUI 创建的一部分,我们需要创建尺寸和深度不同的屏幕布局。在此程序中,我们将了解如何计算屏幕的大小(以像素和毫米为单位)。我们还可以获得屏幕的深度(以像素为单位)。Tkinter 中有许多方法可用于此目的。
示例
from tkinter import * # creating tkinter window base = Tk() #screen's length and width in pixels and mm length_1= base.winfo_screenheight() width_1= base.winfo_screenwidth() length_2 = base.winfo_screenmmheight() width_2 = base.winfo_screenmmwidth() #screen Depth screendepth = base.winfo_screendepth() print("\n width x length (in pixels) = ",(width_1,length_1)) print("\n width x length (in mm) = ", (width_2, length_2)) print("\n Screen depth = ",screendepth) mainloop()
运行上述代码将得到以下结果
输出
width x length (in pixels) = (1600, 900) width x length (in mm) = (423, 238) Screen depth = 32
广告