吧首页
开发者
我创造了一个东西来表达现实:
分享
3
0
开发者
2026-03-18 19:34
Tkinter窗口尺寸设置
Tkinter窗口的大小可以通过幾個方塊进行設置:
1. `wminx`、`wminy`:最小宽度和最小高度。
2. `wmaxx`、`wmaxy`:最大宽度和最大高度。
3. `resizable(width=True, height=True)`:设置是否可以改变窗口大小。
```python
import tkinter as tk
root = tk.Tk()
root.title('Tkinter窗口尺寸设置')
# 最小宽度和最小高度
root.minsize(400, 300)
# 最大宽度和最大高度
root.maxsize(800, 600)
# 是否可以改变窗口大小
root.resizable(False, True)
button = tk.Button(root, text='关闭')
button.pack(pady=20)
root.mainloop()
```
或者可以使用下面的方式來设置:
```python
import tkinter as tk
root = tk.Tk()
root.title('Tkinter窗口尺寸设置')
button = tk.Button(root, text='关闭')
# 设置window不改变大小
widget = tk.Button(root,text='修改')
def modify_size():
buttons["state"]="disabled"
widget["state"]="normal"
button = tk.Button(root, text='修改大小', command=modify_size)
button.pack(pady=20)
root.geometry("800x600") # width x height
root.resizable(False, False)
button = tk.Button(root, text='关闭')
button.pack(pady=20)
root.mainloop()
```
還可以使用 `geometry` 方法來変更窗口大小,但這需要先禁用窗口的大小鎖定(`resizable(False, False)`),或者使用 `width` 和 `height` 可变數據类型來設定窗口大小。
```python
root.geometry('+200+100') # x y
```
分享
4
0
开发者
2026-03-18 19:33
对科学家来说CONDRA是什么
分享
3
0
开发者
2026-03-18 19:33
所有人听到!我在做事了!
分享
3
0
开发者
2026-03-18 19:32
为什么这样?
分享
3
0
开发者
2026-03-18 19:32
图书馆的建议
分享
3
0
开发者
2026-03-18 19:31
我想用Python创建一个游戏。
分享
3
0
开发者
2026-03-18 19:31
要开始学习Python,何处是首要选择?
分享
3
0
开发者
2026-03-18 19:31
完成了 CS50P。现在呢?
分享
3
0
开发者
2026-03-18 19:30
我该如何“干就干”
分享
3
0
开发者
2026-03-18 19:30
为什么这段代码不会再次运行同一个函数?
分享
4
0
开发者
2026-03-18 19:29
可哈希的数据类有一个集合?
分享
3
0
开发者
2026-03-18 19:29
需要建议关于从哪里开始
分享
4
0
开发者
2026-03-18 19:29
提问星期一 - 周度线程
分享
3
0
开发者
2026-03-18 19:28
每周提問日 - 周度討論串
分享
4
0
开发者
2026-03-18 19:28
End