Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Panedwindow
#1
Smile 
(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) Having root.update() in the root resize event, I can drag the sash left/right and, at some pint, get the editText (t5) to not expand and fill (see attachment). If I comment out this root 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()
Image
Reply
#2
I'm not sure why binding to root.configure calls resize when frame1 or frame2 are resized. I found you can filter those out by placing a frame between root and pw and binding that frame's configure event to update.
import tkinter as tk
 
def resize(event):
    print(event)
    root.update()
 
root = tk.Tk()

# Create a frame to get the resize event
top = tk.Frame(root)
top.pack(expand=True, fill=tk.BOTH)
top.bind("<Configure>", resize)

pw = tk.PanedWindow(
    top,
    background="cyan",
    bd=4,
    orient=tk.HORIZONTAL,
    sashrelief=tk.RAISED,
    sashwidth=4,
    showhandle=False,
    sashpad=5,
    sashcursor="sb_h_double_arrow")
pw.pack(fill=tk.BOTH, expand=True)

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

# create scrollbars
xscrollbar = tk.Scrollbar(frame2, orient=tk.HORIZONTAL)
xscrollbar.pack(side=tk.BOTTOM, fill=tk.X)
yscrollbar = tk.Scrollbar(frame2, orient=tk.VERTICAL)
yscrollbar.pack(side=tk.RIGHT, fill=tk.Y)

t5 = tk.Text(frame2, wrap=tk.NONE, xscrollcommand=xscrollbar.set, yscrollcommand=yscrollbar.set)
t5.pack(expand=True, fill=tk.BOTH)
xscrollbar.configure(command=t5.xview)
yscrollbar.configure(command=t5.yview)
for line in range(50):
   t5.insert(tk.END, str(line+1) + " Now is the time for all good men to come to the aid of their party. Every good boy does fine.  The quick brown fox jumps over the lazy dog\n")

pw.update()
pw.sash_place(0, 90, 4)
root.mainloop()
I cannot make your problem occur.
Reply
#3
Your fix worked! Thank you very much!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Need help please properly putting tabs within a PanedWindow JackMack118 2 3,354 Dec-08-2019, 03:02 PM
Last Post: balenaucigasa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020