0

(1) I'm trying to understand why my root.bind("<Configure>", resize) line fires when I drag my panedwindow sash left and right? This does not change the root window's width or height or x or y values.

(2) with root.update() in the resize event, I can move the sash left and right and eventually, get the editText to fail to expand and fill (see attachment). If I comment out this update() then I cannot make that happen.

from tkinter import *
import tkinter as tk

def resize(event):
    root.update()
    print("width", event.width, "height", event.height, "x", event.x, "y", event.y)

root = Tk()
root.title("Test")
root.geometry('600x400+400+350')

pw = tk.PanedWindow(root, background="cyan",
                            bd=4,
                            orient=HORIZONTAL,
                            sashrelief=RAISED,
                            sashwidth=4, # 2 default
                            showhandle=FALSE,
                            sashpad=5, # thickness of the sash background band
                            sashcursor="sb_h_double_arrow")

pw.pack(fill=BOTH, expand=True)

frame1 = tk.Frame(pw)
frame2 = tk.Frame(pw)

pw.add(frame1)
pw.add(frame2)

# create scrollbars
xscrollbar = Scrollbar(frame2, orient='horizontal')  # create X axis scrollbar and assign to frame2
yscrollbar = Scrollbar(frame2, orient='vertical')  # create Y axis scrollbar and assign to frame2
xscrollbar.pack( side = BOTTOM, fill=X )  # bottom side horizontal scrollbar
yscrollbar.pack( side = RIGHT, fill=Y )  # right side vertical scrollbar

t5 = Text(frame2, wrap = 'none', xscrollcommand = xscrollbar.set, yscrollcommand = yscrollbar.set)
for line in range(50):
   t5.insert(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")
t5.pack(expand=True, fill='both') # fill frame with Text widget

pw.update()
#print(pw.sash_coord(0))  # This method returns the location of a sash
# Use this method to reposition the sash selected by index
print(pw.sash_place(0, 90, 4))  # 90 moves the sash left/right

root.bind("<Configure>", resize)

root.mainloop()

enter image description here

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
RalphF
  • 373
  • 3
  • 10
  • 21

1 Answers1

0

I'm trying to understand why my root.bind("", resize) line fires when I drag my panedwindow sash left and right?

When you add a binding to the root window, that binding gets added to every widget. This is because you aren't actually binding to a widget, you are binding to a bind tag.

When you move the sash, that causes the <Configure> event to be posted to the sash. And because of the binding, the function is called.

with root.update() in the resize event, ...

You should never call update inside a handler for an event. This can have a lot of unexpected side effects.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685