-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Are scrollbars on frames doable? #27
Comments
In tcl/tk it's possible. https://stackoverflow.com/questions/39956549/how-to-add-a-scrollbar-to-tcl-frame This tcl/tk code is from Oliver Scholl's post. It produces a nice table on a frame with both scrollbars. The only changes I made were renaming the frame and canvas to improve readability. So... Does anyone know how to get access to the canvas.yview and canvas.xview properties? ` # create canvas with scrollbars # create frame with widgets for {set i 0} {$i <=20} {incr i} { # create frame with buttons # place widgets and buttons # determine the scrollregion # show the canvas |
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.
The text was updated successfully, but these errors were encountered: