如何在 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 生日开业蛋糕祝福语简短