Prev: tcl vs lisp and haskell
Next: www.prevayler.org anyone do an in ram data base with transactionlog in tcl?
From: Dan Halbert on 11 Dec 2009 15:10 Hi - I am seeing a peculiar off-by-1 issue with canvasx and canvasy after setting a canvas scrollregion. I set a scroll region, but no scrolling has happened. I would expect [.canvas canvasx 0] to be == 0, and the same for canvasy. However, if the scrollregion is smaller or the same size as the canvas, then I get -1 for canvasx and canvasy. Some simple code to demonstrate this is below. This is distilled out of an image markup tool (in Tkinter, actually), where I want to mark points precisely. There are three possible lines that set a scrollregion: smaller than the canvas, same size, and larger. Only the last case does not affect canvasx and canvasy. To get results, run the script with wish, and then click in the window to print out canvasx and canvasy values before and after setting the scrollregion. Thanks very much for any explanation about this, or is it a bug? (tested in Ubuntu wish8.4 and wish8.5) Dan #---------------- canvas .canvas -width 300 -height 300 grid .canvas bind .canvas <Button-1> {setScrollRegion %x %y} proc setScrollRegion {x y} { printCanvasxy # Uncomment one of these three lines .canvas configure -scrollregion [list 0 0 290 290] ; # canvasx (0)= -1.0, canvasy(0)= -1.0 # .canvas configure -scrollregion [list 0 0 300 300] ; # canvasx (0)= -1.0, canvasy(0)= -1.0 # .canvas configure -scrollregion [list 0 0 310 310] ; # canvasx (0)= 0.0, canvasy(0)= 0.0 printCanvasxy } proc printCanvasxy {} { puts "canvasx(0)= [.canvas canvasx 0], canvasy(0)= [.canvas canvasy 0]" }
From: Peter Spjuth on 11 Dec 2009 17:59
On Dec 11, 9:10 pm, Dan Halbert <halb...(a)halwitz.org> wrote: > Hi - I am seeing a peculiar off-by-1 issue with canvasx and canvasy > after setting a canvas scrollregion. I set a scroll region, but no > scrolling has happened. I would expect [.canvas canvasx 0] to be == 0, > and the same for canvasy. However, if the scrollregion is smaller or > the same size as the canvas, then I get -1 for canvasx and canvasy. When created, coordinate 0,0 is not visible in a canvas. Usually due to -highlightthickness and/or -selectborderwidth. If -confine is true (the default), setting scrollregion to {0 0 290 290} will scroll the canvas until the entire region is visible. This gives the change in canvasx/y you see. The other scrollregion settings in your example does not cause any scrolling since the visible canvas is a subregion of the scrollregion. /Peter |