如何在 Tkinter 中获取屏幕尺寸?
Tkinter最初创建一个窗口或框架对象,其中显示所有小部件、框架。
Tkinter组件根据用户定义的几何形状调整窗口大小和宽度。
为了获得屏幕尺寸,我们可以使用winfo_screenwidth()which返回屏幕宽度和屏幕winfo_screenheight()高度(以像素为单位)。
示例
在这个例子中,我们将打印屏幕尺寸作为输出,
#Import the required libraries
from tkinter import *
#Create an instance of tkinter frame
win= Tk()
#Set the geometry of frame
win.geometry("650x250")
#Get the current screen width and height
screen_width = win.winfo_screenwidth()
screen_height = win.winfo_screenheight()
#Print the screen size
print("屏幕宽度:", screen_width)
print("屏幕高度:", screen_height)
win.mainloop()输出结果运行代码将显示一个窗口并打印屏幕大小。
屏幕宽度: 1366 屏幕高度: 768
热门推荐
10 读书祝福语女生短句简短
11 感谢同事新婚祝福语简短
12 感谢教官文案祝福语简短
13 员工聚会蛋糕祝福语简短
14 元宵发客户祝福语简短
15 给团队信心祝福语简短
16 医美的祝福语大全简短
17 异国姻缘的祝福语简短
18 兄妹拍照祝福语简短的话