Come congelare le dimensioni del telaio della finestra Tkinter
In alcuni scenari, vogliamo che la dimensione del frame della finestra Tkinter sia congelata, o in altre parole, il frame non è ridimensionabile. Per esempio, il frame della finestra mantiene lo stesso non importa che il widget dell’etichetta nel frame sia troppo lungo o troppo corto.
Metodo resizable del frame
resizable(width= , height=) configura la dimensione della finestra del frame ridimensionabile o meno in width e height.
resizable(width = False) congela solo la larghezza della finestra, mentre resizable(height = False) congela solo l’altezza della finestra. L’intera dimensione della finestra viene congelata usando resizable(width=False, height=False), o semplicemente 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()
Metodo minsize e maxsize del frame
I metodi minsize e maxsize sono normalmente usati per impostare la dimensione minima e massima della finestra, ma potrebbero anche congelare la dimensione della finestra se si impostano entrambe le dimensioni minime e massime per essere identiche.
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 Facebook