From looking at this for a few days, I don't understand is why the pandedwindow widget is not all the way down to the top of the bottom frame. If I block out the frame portion, the PanedWindow goes all the way to the bottom of the window.
Please feel free to criticize or give comments on how I can improve my program in terms of using class.
import tkinter as t
def main():
root = t.Tk()
root.geometry("350x470")
root.config(background="LightBlue4")
root.title("basic window")
app = Application (root)
root.mainloop()
class Application():
def __init__(self, parent):
self.window = parent
self.panes=t.PanedWindow(self.window, sashwidth=3)
self.panes.pack(fill=t.BOTH, expand="yes")
self.frame1=t.Frame(self.window, bg="yellow", bd=2, relief=t.RIDGE)
self.frame1.pack(anchor=t.S, fill=t.X, expand=1)
self.createWidgets()
def createWidgets(self):
self.entry=t.Entry(self.frame1, width=25)
self.entry.pack(side=t.LEFT, expand=1)
self.label2=t.Label(self.frame1, text="Update ", fg = "light green", bg = "dark green", font = "Helvetica 16 bold italic" , bd=2, relief=t.RAISED)
self.label2.pack(side=t.LEFT, fill=t.X, padx=5)
self.label3=t.Label(self.frame1, text="Quit", fg = "blue", bg = "yellow", font = "Verdana 12 bold" , bd=2, relief=t.RAISED)
self.label3.pack(side=t.LEFT, fill=t.X, padx=5)
self.left = t.Label(self.window, text="Left Pane", bd=4, bg="tan", relief=t.FLAT)
self.left.pack()
self.right = t.Label(self.window, text="Right Pane", bd=4, bg="light cyan", relief=t.FLAT)
self.right.pack()
self.panes.add(self.left, stretch="always")
self.panes.add(self.right )
self.panes.sash_place(0,120,0)
if __name__ == '__main__':
main()
The paned window does not extend the full vertical height because it is sharing space with self.frame1
. Both have been packed with the option to expand into the available space, so they end up each taking half.
It you turn expansion off on self.frame1
, the paned window will take all of the available space:
self.frame1.pack(anchor=t.S, fill=t.X, expand=False)
I don't understand is why the pandedwindow widget is not all the way down to the top of the bottom frame.
That is because the way you packed self.frame1
and self.panes
places these 2 widgets on top of each other. That is what you can see when comment this line: #self.createWidgets()
:
If you want the PaneWindow widget to stretch down, you will need to pack self.frame1
and self.panes
side by side using the side
option:
self.panes.pack(fill=t.BOTH, expand="yes", side = t.LEFT)
self.frame1.pack(anchor=t.S, fill=t.X, expand=1, side = t.LEFT)
Result:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.