Tkinter ウィンドウフレームのサイズを固定する方法

場合によっては、Tkinter ウィンドウのサイズをフリーズしたい、つまり、フレームのサイズを変更できません。たとえば、フレーム内のタブ付きウィンドウウィジェットが長すぎても短すぎても、ウィンドウフレームは同じままです。
フレームワークの resizable
メソッド
resizable(width= , height=)
は、ウィンドウサイズの width
と height
を変更できるかどうかを設定します。
resizable(width = False)
はウィンドウの幅のみをフリーズし、resizable(height = False)
はウィンドウの高さのみをフリーズします。
resizable(width=False, height=False)
を使用すると、ウィンドウサイズ全体がフリーズするか、より簡潔な resizable(False, False)
が使用されます。
try:
import Tkinter as tk
except:
import tkinter as tk
app = tk.Tk()
app.title("Frame Window Size Frozen")
app.geometry('300x200')
app.resizable(width=False, height=False)
app.mainloop()
フレーム minsize
と maxsize
方法
minsize
と maxsize
方法は、最小と最大のウィンドウサイズを設定するのに一般的ですが、最小と最大のサイズを同じに設定すると、ウィンドウサイズを固定する目的も達成されます。
try:
import Tkinter as tk
except:
import tkinter as tk
app = tk.Tk()
app.title("Frame Window Size Frozen")
app.minsize(width=600, height=400)
app.maxsize(width=600, height=400)
app.mainloop()
Founder of DelftStack.com. Jinku has worked in the robotics and automotive industries for over 8 years. He sharpened his coding skills when he needed to do the automatic testing, data collection from remote servers and report creation from the endurance test. He is from an electrical/electronics engineering background but has expanded his interest to embedded electronics, embedded programming and front-/back-end programming.
LinkedIn