resizable()方法用於允許Tkinter根窗口根據用戶需要更改其大小,我們也可以禁止調整Tkinter窗口的大小。因此,本質上,如果用戶要創建固定大小的窗口,則可以使用此方法。
如何使用:
-> import tkinter -> root = Tk() -> root.resizable(height = None, width = None)
要傳遞的參數:
-> In
resizable()
method user can pass either positive integer or True, to make the window resizable.
-> To make window non-resizable user can pass 0 or False.
代碼1:允許根窗口更改其大小
# importing only those functions
# which are needed
from tkinter import *
from tkinter.ttk import *
from time import strftime
# creating tkinter window
root = Tk()
root.title('Resizable')
root.geometry('250x100')
Label(root, text = 'It\'s resizable').pack(side = TOP, pady = 10)
# Allowing root window to change
# it's size according to user's need
root.resizable(True, True)
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()
root.title('Resizable')
root.geometry('250x100')
Label(root, text = 'It\'s non-resizable').pack(side = TOP, pady = 10)
# Restricting root window to change
# it's size according to user's need
root.resizable(0, 0)
mainloop()
輸出:
您可能會觀察到藍色圓圈內的部分被禁用,即無法更改窗口的大小。
相關用法
- Python Tkinter minsize()用法及代碼示例
- Python Tkinter place()用法及代碼示例
- Python Tkinter maxsize()用法及代碼示例
- Python Tkinter pack()用法及代碼示例
- Python Tkinter grid()用法及代碼示例
- Python Tkinter iconphoto()用法及代碼示例
- Python Tkinter destroy()用法及代碼示例
注:本文由純淨天空篩選整理自sanjeev2552大神的英文原創作品 resizable() method in Tkinter | Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。