如何在 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
热门推荐
5 带清的简短祝福语
10 高考前祝福语简短字句
11 好朋友夫妻祝福语简短
12 启程出发路途祝福语简短
13 女生成年祝福语简短
14 龙年简短祝福语有哪些
15 鼓掌祝福语简短10字
16 女儿生日祝福语说说简短
17 妹妹生日祝福语简短唯美
18 生日祝福语简短独特的