此方法用于设置根窗口的最大大小(可以扩展窗口的最大大小)。用户仍然可以将窗口尺寸缩小到最小。

用法:

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()方法,该方法用于设置窗口的最小大小。