如何设置大小固定的 Tkinter 窗口?
有时, Tkinter 框架会根据小组件的大小自动调整大小。为了使框架尺寸固定,我们必须停止小部件调整框架大小。所以有以下三种方法:
布尔值 pack_propagate(True/False)方法防止小部件调整框架大小。
resize(x,y)方法防止窗口调整大小。
Pack(fill, expand)值会将窗口调整为其在几何中的定义大小。
从本质上说,Tkinter 框架内的所有小组件都将具有响应性,并且无法调整大小。
示例
from tkinter import *
win= Tk()
win.geometry("700x300")
#Don't allow the screen to be resized
win.resizable(0,0)
label= Label(win, text= "Select an option", font=('Times New Roman',12))
label.pack_propagate(0)
label.pack(fill= "both",expand=1)
def quit():
win.destroy()
#Create two buttons
b1= Button(win, text= "Continue")
b1.pack_propagate(0)
b1.pack(fill="both", expand=1)
b2= Button(win, command= quit, text= "Quit")
b2.pack_propagate(0)
b2.pack(fill="both", expand=1)
win.mainloop()输出
运行上述代码将使窗口的大小保持不变,不可调整大小。

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP