python - tkinter canvas in grid has extra space -
i have canvas inside frame , i've said canvas should 250x250. reason being created bigger, space on right , bottom. here's code... ideas?
from tkinter import * tkinter import ttk player import player0 alpha = ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z') class gui(frame): def __init__(self, master): frame.__init__(self, master) self.boardsize = 250 self.sqsize = self.boardsize//5 master.title("canvas space") self.initialdraw() self.grid(row=0,column=0) def initialdraw(self): mainframe = ttk.frame(self, padding=(5,5,5,5)) mainframe.grid(column=0, row=0, sticky=(n, s, e, w)) self.board = canvas(mainframe, width=self.boardsize, height=self.boardsize,bg='white') self.board.grid(row=1,column=0) row in range(5): col in range(5): top = row * self.sqsize left = col * self.sqsize bottom = row * self.sqsize + self.sqsize -2 right = col * self.sqsize + self.sqsize -2 rect = self.board.create_rectangle(left,top,right,bottom,outline='gray',fill='') self.board.focus_set() if __name__ == '__main__': tk = tk() gui = gui(tk) tk.mainloop()
the result this:
i rather avoid white gutter on right , bottom of canvas after smaller squares have been drawn.
the canvas has border, controlled borderwidth
attribute. has border controlled highlightthickness
attribute. set both of 0 , canvas should size set be.
the border
attribute typically used provide 3d effect -- raised border, sunken boarder, or couple other variations. highlightthickness
(and highlightcolor
) attributes define solid outline used denote widget has keyboard focus.
Comments
Post a Comment