Skip to content

Are scrollbars on frames doable? #27

@john157157

Description

@john157157

Working off of Bryan Oakley's TKinter example here: https://stackoverflow.com/questions/3085696/adding-a-scrollbar-to-a-group-of-widgets-in-tkinter/3092341#3092341 I only got this far:

`
func NewWindow() *Window {
mw := &Window{tk.RootWindow()}
mw.ResizeN(800, 600)
canvas := tk.NewCanvas(mw, tk.WidgetAttrWidth(800), tk.WidgetAttrHeight(600), tk.CanvasAttrBorderWidth(0), tk.CanvasAttrBackground("white"))
frame := tk.NewFrame(canvas, tk.WidgetAttrWidth(750), tk.WidgetAttrHeight(270), tk.WidgetAttrInitUseTheme(false))
frame.SetNativeAttribute("background", "black")
// populate with some labels
for i := 0; i < 40; i++ {
lbl := tk.NewLabel(frame, "label "+strconv.Itoa(i))
lbl.SetBackground("#ccc")
tk.Grid(lbl, tk.GridAttrRow(i), tk.GridAttrColumn(0), tk.GridAttrPadx(5), tk.GridAttrPady(5), tk.GridAttrSticky(tk.StickyAll))
}
vertScrollbar := tk.NewScrollBar(mw, tk.Vertical, tk.WidgetAttrInitUseTheme(false))
vertScrollbar.SetNativeAttribute("command", "canvas yview") // bad window pathname error
tk.Grid(canvas, tk.GridAttrRow(0), tk.GridAttrColumn(0), tk.GridAttrSticky(tk.StickyAll))
tk.Grid(frame, tk.GridAttrRow(0), tk.GridAttrColumn(0), tk.GridAttrPadx(15), tk.GridAttrPady(15))
tk.Grid(vertScrollbar, tk.GridAttrRow(0), tk.GridAttrColumn(1), tk.GridAttrSticky(tk.StickyNS))
return mw
}

func main() {
tk.MainLoop(func() {
mw := NewWindow()
mw.SetTitle("ATK Sample")
mw.Center(nil)
mw.ShowNormal()
mw.BindKeyEvent(func(e *tk.KeyEvent) {
if e.Event.KeyCode == 9 { // esc key
tk.Quit()
}
})
})
}

The problem is these Python/TKinter lines:
vsb = tk.Scrollbar(root, orient="vertical", command=canvas.yview)
canvas.configure(yscrollcommand=vsb.set)
frame.bind("", lambda event, canvas=canvas: onFrameConfigure(canvas))
`

Any help appreciated.

If the focus of the question feels too narrow then how about example code showing attaching a scrollbar to anything?

I'm sorry that my code isn't appropriately indented. I clicked the "<>" icon, copy/pasted and lost the indents.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions