如何利用 Tkinter 防止視窗調整大小?


Tkinter 視窗可以透過懸停並拉動視窗來自動調整大小。我們可利用 resizable(布林值) 方法停用 resizable 屬性。我們將會向此方法傳遞 false 值,這樣將會停用視窗調整大小的功能。

示例

#Import the tkinter library
from tkinter import *

#Create an instance of tkinter frame
win = Tk()

#Set the geometry
win.geometry("650x250")

Label(win, text= "Hello World", font=('Times New Roman bold',
20)).pack(pady=20)

#Make the window resizable false
win.resizable(False,False)

win.mainloop()

輸出

執行以上程式碼將會顯示以下 tkinter 視窗,但是你將無法調整它的大小。

更新於: 2021-03-27

14K+ 瀏覽次數

開啟你的 職業生涯

完成課程,獲得認證

開始學習
廣告
© . All rights reserved.