เริ่มแรก 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