Tkinter Canvas create_window()

微笑、不失礼 提交于 2019-11-30 10:08:26

You can bind self._canvas with the event <Configure>, and then call itemconfig with the id of the frame added to the canvas (not directly the reference to the widget):

def __init__(self, rows, cols, master=None):
    # ...
    self._frame_id = self._canvas.create_window(0, 0, window=self._tableFrame, anchor=N+W)
    self._canvas.pack(side=LEFT, fill=BOTH, expand=True)
    self._canvas.bind("<Configure>", self.resize_frame)

def resize_frame(self, e):
    self._canvas.itemconfig(self._frame_id, height=e.height, width=e.width)

By the way, I recommend you to rewrite your import statements, which in my opinion are quite repetitive and unpythonic:

import Tkinter as tk
# Use tk.Tk, tk.Canvas, etc.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!