如何获取 Tkinter 中的屏幕大小?
Tkinter 最初创建一个窗口或框架对象,所有小部件、框架都在其中显示。
Tkinter 组件根据用户定义的几何形状调整窗口大小和宽度。
为了获取屏幕大小,我们可以使用 winfo_screenwidth() 来返回屏幕的宽度,并使用 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:", screen_width)
print("Screen height:", screen_height)
win.mainloop()输出
运行代码将显示一个窗口并打印屏幕大小。
Screen width: 1366 Screen height: 768
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP