此方法用於設置根窗口的最大大小(可以擴展窗口的最大大小)。用戶仍然可以將窗口尺寸縮小到最小。
用法:
master.maxsize(height, width)
此處,高度和寬度以像素為單位。
代碼1:
# importing only those functions
# which are needed
from tkinter import *
from tkinter.ttk import *
from time import strftime
# creating tkinter window
root = Tk()
# Adding widgets to the root window
Label(root, text = 'GeeksforGeeks',
font =('Verdana', 15)).pack(side = TOP, pady = 10)
Button(root, text = 'Click Me !').pack(side = TOP)
mainloop()
輸出:
窗口的初始大小(未設置窗口的最大大小)
窗口的擴展尺寸(此窗口可以擴展到屏幕尺寸,因為尺寸不固定)。
代碼2:固定根窗口的最大大小
# importing only those functions
# which are needed
from tkinter import *
from tkinter.ttk import *
from time import strftime
# creating tkinter window
root = Tk()
# Fixing the size of the root window.
# No one can now expand the size of the
# root window than the specified one.
root.maxsize(200, 200)
# Adding widgets to the root window
Label(root, text = 'GeeksforGeeks',
font =('Verdana', 15)).pack(side = TOP, pady = 10)
Button(root, text = 'Click Me !').pack(side = TOP)
mainloop()
輸出:
窗口的最大擴展尺寸
注意:Tkinter還提供了minsize()方法,該方法用於設置窗口的最小大小。
相關用法
- Python Tkinter iconphoto()用法及代碼示例
- Python Tkinter pack()用法及代碼示例
- Python Tkinter resizable()用法及代碼示例
- Python Tkinter place()用法及代碼示例
- Python Tkinter destroy()用法及代碼示例
- Python Tkinter minsize()用法及代碼示例
- Python Tkinter grid()用法及代碼示例
注:本文由純淨天空篩選整理自sanjeev2552大神的英文原創作品 maxsize() method in Tkinter | Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。