According to this question, binding a Configure
event type to the root window detects the movement of the sash of a tkinter Panedwindow. For example,
root.bind("<Configure>", resize)
However, I inferred from @BryanOakley's answer that it is not the correct approach.
Hence, what is the correct approach to detect the movement of a sash of a ttk.Panedwindow
?
Test Script (based on test script by question):
import tkinter as tk
import tkinter.ttk as ttk
class App(ttk.PanedWindow):
def __init__(self, parent, orient="horizontal"):
super().__init__(parent, orient=orient)
self.parent = parent
self.frame1 = ttk.Frame(self)
self.frame2 = ttk.Frame(self)
self.add(self.frame1)
self.add(self.frame2)
# create scrollbars
self.xsb = ttk.Scrollbar(self.frame2, orient='horizontal') # create X axis scrollbar and assign to frame2
self.ysb = ttk.Scrollbar(self.frame2, orient='vertical') # create Y axis scrollbar and assign to frame2
self.xsb.pack(side=tk.BOTTOM, fill=tk.X ) # bottom side horizontal scrollbar
self.ysb.pack(side=tk.RIGHT, fill=tk.Y ) # right side vertical scrollbar
self.t5 = tk.Text(self.frame2, wrap='none',
xscrollcommand=self.xsb.set,
yscrollcommand=self.ysb.set)
for line in range(50):
self.t5.insert(tk.END, str(line+1) + " Now is the time for all good men to come to the aid of their party. Now is the time for all good men to come to the aid of their party.\n")
self.t5.pack(expand=True, fill='both') # fill frame with Text widget
self.bind("<Configure>", self.resize)
def resize(self, event):
self.update_idletasks()
print("width", event.width, "height", event.height, "x", event.x, "y", event.y)
if __name__ == "__main__":
root = tk.Tk()
root.title("Test")
root.geometry('600x400+400+350')
app = App(root)
app.pack(fill=tk.BOTH, expand=True)
root.mainloop()