我大部分都是从here复制了代码,它确实产生了一个用画布和一个滚动条组成的新框架,但是滚动条不起作用/没有启用。这是创建新窗口的方法。
def ReviewTest(self, parsedFile = None):
if parsedFile is None:
return
else:
reviewTopLevel = Tk.Toplevel(self)
reviewTopLevel.geometry("%dx%d%+d%+d" % (600,400,0,0))
verticalScroll = Tk.Scrollbar(reviewTopLevel, orient=Tk.VERTICAL)
verticalScroll.pack(fill=Tk.Y, side=Tk.RIGHT, expand=Tk.FALSE)
canvas = Tk.Canvas(reviewTopLevel, bd=0, highlightthickness=0, yscrollcommand=verticalScroll.set)
canvas.pack(side=Tk.LEFT, fill=Tk.BOTH, expand=Tk.TRUE)
verticalScroll.config(command=canvas.yview)
canvas.xview_moveto(0)
canvas.yview_moveto(0)
self.interior = interior = Tk.Frame(canvas)
interiorId = canvas.create_window(0,0, window=interior, anchor=Tk.NW)
reviewTopLevel.wm_title("Review Test")
def _configure_interior(event):
size = (reviewTopLevel.winfo_reqwidth(), reviewTopLevel.winfo_reqheight())
canvas.configure(scrollregion="0 0 %s %s" % size)
if reviewTopLevel.winfo_reqwidth() != canvas.winfo_width():
canvas.configure(width=reviewTopLevel.winfo_width())
interior.bind('<Configure>', _configure_interior)
def _configure_canvas(event):
if reviewTopLevel.winfo_reqwidth() != canvas.winfo_reqwidth():
canvas.configure(width=reviewTopLevel.winfo_reqwidth())
canvas.bind('<Configure>', _configure_canvas)
self.canvasWidgets = []
for keyIndex, key in enumerate(parsedFile.GetKeys()):
category = Tk.Label(canvas, text=key, anchor=Tk.W)
category.grid(row = 0, column = keyIndex, sticky=Tk.EW)
self.canvasWidgets.append(category)
currentColumnKey = parsedFile.GetColumns()[key]
for dataIndex in range(0, len(currentColumnKey)):
data = Tk.Entry(canvas)
data.insert(0, currentColumnKey[dataIndex])
data.grid(row = dataIndex + 1, column = keyIndex, sticky=Tk.EW)
self.canvasWidgets.append(data)
答案 0 :(得分:1)
我没有仔细阅读其他帖子,添加的小部件应该设置为内部,而不是画布。
self.canvasWidgets = []
for keyIndex, key in enumerate(parsedFile.GetKeys()):
category = Tk.Label(interior, text=key, anchor=Tk.W)
category.grid(row = 0, column = keyIndex, sticky=Tk.EW)
self.canvasWidgets.append(category)
currentColumnKey = parsedFile.GetColumns()[key]
for dataIndex in range(0, len(currentColumnKey)):
data = Tk.Entry(interior)
data.insert(0, currentColumnKey[dataIndex])
data.grid(row = dataIndex + 1, column = keyIndex, sticky=Tk.EW)
self.canvasWidgets.append(data)