Specify relative width of two embedded "entries" within "text" widget Specify relative width of two embedded "entries" within "text" widget tkinter tkinter

Specify relative width of two embedded "entries" within "text" widget


Within a text widget? No, there is no direct support for relative widths. within a frame? yes. If you are putting them in a text widget (I presume, so you can scroll them) you have to manage the widths yourself. You can add a binding to the <Configure> event of the text widget. This fires when the text widget changes size, and you can resize all the widgets at that point.

The easiest thing is to put them in a frame using grid, then put the frame in a canvas so you can scroll it.

Here's an example:

import Tkinter as tkclass SampleApp(tk.Tk):    def __init__(self, *args, **kwargs):        tk.Tk.__init__(self, *args, **kwargs)        self.canvas = tk.Canvas(self, width=200, highlightthickness=0)        self.vsb = tk.Scrollbar(orient="vertical", command=self.canvas.yview)        self.canvas.configure(yscrollcommand=self.vsb.set)        self.vsb.pack(side="right", fill="y")        self.canvas.pack(side="left", fill="both", expand=True)        self.container = tk.Frame(self.canvas, borderwidth=0, highlightthickness=0)        self.container.grid_columnconfigure(0, weight=1)        self.container.grid_columnconfigure(1, weight=1)        for i in range(30):            e1 = tk.Entry(self.container)            e2 = tk.Entry(self.container)            e1.grid(row=i, column=0,sticky="ew")            e2.grid(row=i, column=1,sticky="ew")            e1.insert(0, "find %s" % i)            e2.insert(0, "replace %s" % i)        self.canvas.create_window((0,0), anchor="nw", window=self.container, tags="container")        self.canvas.configure(scrollregion=self.canvas.bbox("all"))        self.canvas.bind("<Configure>", self.OnCanvasConfigure)    def OnCanvasConfigure(self, event):        self.canvas.itemconfigure("container", width=event.width)        self.canvas.configure(scrollregion=self.canvas.bbox("all"))if __name__ == "__main__":    app = SampleApp()    app.mainloop()