Thread: baffled

    #1
  1. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,988
    Rep Power
    510

    baffled


    Class c draws a grid a window. When the tile size is 8 it draws as I expect. When the tile size is greater than 8, in an integral way, some of the lines don't show.
    Fails on linux with one release of python3, fails on windows with a different python3 release, and as I recall in a different way.

    I'd like to use a tile size larger than 8 because my eyesight isn't so good. Something like a tile_size pixel font is going into the grid in the finished program.

    Thanks, Dave.

    With tile_size of 20 or so the clipped, vanished, undrawn lines are quite obvious.
    Code:
    #! python3
    import tkinter
    
    border_size = 9
    
    class c:
    
        def __init__(self, root = None, tile_size = 9, title = 'fail'):
            if root == None:
                root = tkinter.Tk()
                size = '{}x{}'.format(* 2 * (27 * tile_size + 4 * border_size,))
                print(size)
                root.wm_geometry(size)
                root.wm_title(title)
            self.root = root
            c = self.canvas = tkinter.Canvas(root)
            i = 3
            h = border_size // 2
            n = h + i * (border_size + 9 * tile_size)
            l = c.create_line
            for i in range(4):
                m = (border_size // 2) + i * (border_size + 9 * tile_size)
                l(m, h, m, n, fill = 'black', width = 3)
                l(h, m, n, m, fill = 'black', width = 3)
                print(h,m,n)
            c.pack()
    
        def update(self):
            self.root.update()
    
        def mainloop(self):
            self.root.mainloop()
    
    a = c(tile_size = 9, title = 'fail with 9 or larger')
    a.update()
    
    print()
    
    b = c(tile_size = 8, title = 'success')
    b.update()
    
    input('enter terminates')
    Last edited by b49P23TIvg; May 14th, 2019 at 10:24 AM. Reason: code modified for uniform treatment of objects a and b .
    [code]Code tags[/code] are essential for python code and Makefiles!
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,988
    Rep Power
    510
    Improvements aren't coming to me. :-(
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,988
    Rep Power
    510
    The problem finally troubled me enough to search the internet. A stackoverflow answer says to tell the pack manager more information.
    canvas.pack(expand = tkinter.TRUE, fill = tkinter.BOTH)
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo