繁体   English   中英

在 tkinter 中调整 window 的大小时动态调整小部件的大小

[英]Dynamically resize widget's when resizing a window in tkinter

有没有办法在调整 tkinter 中的 window 的大小时动态调整小部件的大小?

这是代码:

from tkinter import *

root = Tk()
root.geometry("777x575")

text = Text(root , width = 75 , height = 25)
text.grid(row = 0 , column = 0)

scrollbar = Scrollbar(root , command = text.yview)
scrollbar.grid(row = 0 , column = 1 , sticky = N+S+E+W)

text.config(yscrollcommand = scrollbar.set)

button = Button(root , text = "Sample Button")
button.grid(row = 1 , column = 0 , pady = 20)

mainloop()

当我调整 window 的大小时,小部件的宽度和高度保持不变

我想要的是根据窗口的大小动态调整我的 window 内的小部件的大小。

有没有办法在 tkinter 中实现这一点?

如果有人可以帮助我,那就太好了。

试试这个原始源代码示例:

from tkinter import *

root = Tk()
root.geometry("777x575")
root.columnconfigure(0, weight=1)
root.columnconfigure(1, weight=2)

root.rowconfigure(0, weight=1)

text = Text(root, width = 95 , height = 95)
text.grid(column=0, row=0, ipadx=500, ipady=10, sticky="NSEW")

scrollbar = Scrollbar(text, orient=VERTICAL)
scrollbar.pack(fill=Y, side=RIGHT)

button = Button(root, text = "Sample Button")
button.grid(column=0, row=1, ipadx=500, ipady=10, sticky="NSEW")

mainloop()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM