มีสองวิธีในการรับหน้าต่างที่ขยายให้ใหญ่สุดโดยอัตโนมัติใน Tkinter
- เราสามารถใช้วิธี state() ของ Tkinter และเรียกใช้ด้วยแอตทริบิวต์ "zoomed" .
root.state("zoomed") - วิธีที่สองคือการใช้ แอตทริบิวต์ วิธีการของ Tkinter พร้อมพารามิเตอร์ "-fullscreen" และตั้งค่าเป็น จริง .
โดยค่าเริ่มต้น Tkinter จะสร้างหน้าต่างที่มีขนาดที่กำหนดไว้ล่วงหน้า ขนาดของหน้าต่างสามารถปรับแต่งได้โดยใช้วิธีการทางเรขาคณิต ตัวอย่างเช่น
root.geometry("700 x 350")
ตัวอย่างที่ 1
# Import the required libraries
from tkinter import *
# Create an instance of tkinter frame
root=Tk()
# Create a label
Label(root, text="Welcome to Tutorialspoint", font="Calibri, 20").pack(pady=20)
# Maximize the window Size using state property
root.state('zoomed')
root.mainloop() ผลลัพธ์
มันจะสร้างผลลัพธ์ต่อไปนี้ -

ตัวอย่างที่ 2
ตอนนี้ มาปรับแต่งโค้ดและใช้ แอตทริบิวต์ วิธีการแทน สถานะ วิธีการ
# Import the required libraries
from tkinter import *
# Create an instance of tkinter frame
root=Tk()
# Create a label
Label(root, text="Welcome to Tutorialspoint", font="Calibri, 20").pack(pady=20)
# Maximize the window Size using attributes method
root.attributes('-fullscreen', True)
root.mainloop() ผลลัพธ์
มันจะสร้างผลลัพธ์ต่อไปนี้ -
