Tkinter Canvas create_window()

前端 未结 1 1083
情深已故
情深已故 2020-12-31 17:26

I\'m trying to use Tkinter Canvas (self._canvas) to create window using create_window function. The window field for

相关标签:
1条回答
  • 2020-12-31 17:50

    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.
    
    0 讨论(0)
提交回复
热议问题