1

I'm adding several widgets to a Frame which is located in a tix.NoteBook. When there are too much widgets to fit in the window, I want to use a scrollbar, so I put tix.ScrolledWindow inside that Frame and add my widgets to this ScrolledWindow instead.

The problem is that when using the grid() geometry manager, the scrollbar appears, but it is not working (The drag bar occupies the whole scroll bar).

from Tkinter import *
import Tix

class Window:

    def __init__(self, root):

        self.labelList = []
        self.notebook = Tix.NoteBook(root, ipadx=3, ipady=3) 
        self.notebook.add('sheet_1', label="Sheet 1", underline=0) 
        self.notebook.add('sheet_2', label="Sheet 2", underline=0)
        self.notebook.add('sheet_3', label="Sheet 3", underline=0)
        self.notebook.pack()
        #self.notebook.grid(row=0, column=0)

        tab1=self.notebook.sheet_1
        tab2=self.notebook.sheet_2
        tab3=self.notebook.sheet_3



        self.myMainContainer = Frame(tab1)
        self.myMainContainer.pack()
        #self.myMainContainer.grid(row=0, column=0)

        scrwin = Tix.ScrolledWindow(self.myMainContainer, scrollbar='y') 
        scrwin.pack()
        #scrwin.grid(row=0, column=0) 
        self.win = scrwin.window


        for i in range (100):
            self.labelList.append((Label(self.win)))
            self.labelList[-1].config(text= "Bla", relief = SUNKEN)
            self.labelList[-1].grid(row=i, column=0, sticky=W+E)

root = Tix.Tk()
myWindow = Window(root)

root.mainloop()

Whenever I change at least one of the geometry managers from pack() to grid(), the problem occurs. (Actually, I'd prefer using grid() for all containers.)

When I don't use the NoteBook widget, the problem does not occur either. The other examples here all seem to rely on pack(). Any ideas?
Many thanks,
Sano

4

1 回答 1

2

我没有使用'tix.scrolledWindow'就解决了它。相反,我在这里选择了 Fred Lundh 建议的自动滚动条。主要问题是对 NoteBook 小部件的适应。首先,我尝试将滚动条放在根目录,这样它们就会包围整个窗口。现在,我想在更改选项卡时更改滚动条的挂钩,但是笔记本的“raisecmd”不起作用。接下来,我想在每个选项卡上使用 configure 事件——每当一个新选项卡出现时,它的大小就会改变并调用 configure。
好吧,经过多次尝试但从未感到满意,我改变了方法并将滚动条放在里面的选项卡。选项卡和所有子容器必须获得 'grid_columnconfigure(0, weight=1)' 和 'grid_rowconfigure(0, weight=1)' 设置,否则它们不会随选项卡一起增长。

于 2010-04-08T18:15:25.367 回答