如何在 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 好听的元旦简短祝福语