此方法用于设置根窗口的最大大小(可以扩展窗口的最大大小)。用户仍然可以将窗口尺寸缩小到最小。
用法:
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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。