如何使窗口适合tkinter中的内容?

时间:2012-03-18 09:34:14

标签: python tkinter

下面是一些示例代码。窗口没有调整大小(python3.2,在Mac上,从macports)。有没有办法可以修改它以便调整窗口大小?感谢。

import tkinter
import time

root = tkinter.Tk()
can = tkinter.Canvas(root, width = 10, height = 10)
can.pack()

for i in range(10):
    can.configure(width = i * 50, height = i * 50)
    root.update()
    print(i)
    time.sleep(0.5)

1 个答案:

答案 0 :(得分:1)

也许试试这个:

import tkinter
import time

root = tkinter.Tk()
can = tkinter.Canvas(root, width = 10, height = 10)
can.rowconfigure(0, weight=1)
can.columnconfigure(0, weight=1)
can.grid()

root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)

for i in range(10):
    can.configure(width = i * 50, height = i * 50)
    root.update()
    print(i)
    time.sleep(0.5)