tkinter canvas not drawing top and left linesttk tkinter multiple frames/windowsSize limitations of Tkinter grid managerHow to clear Tkinter Canvas?Drawing Labels on a Canvas using TkinterDrawing a image to a tkinter canvasIs there a way of drawing non-canvas lines in Tkinter?TkInter Frame doesn't load if another function is calledPython Multiprocessing Drawing to Tkinter CanvasIn python, with tkinter canvas, is there a way to draw an infinite line?Tkinter inserts separating space between two widgets(canvases)
The art of clickbait captions
Is Jon Snow the last of his House?
Website returning plaintext password
Why would Ryanair allow me to book this journey through a third party, but not through their own website?
NIntegrate doesn't evaluate
Does this strict reading of the rules allow both Extra Attack and the Thirsting Blade warlock invocation to be used together?
Why did Theresa May offer a vote on a second Brexit referendum?
Why aren't space telescopes put in GEO?
Is it truly impossible to tell what a CPU is doing?
Dad jokes are fun
Construct a word ladder
Can a person survive on blood in place of water?
Did 20% of US soldiers in Vietnam use heroin, 95% of whom quit afterwards?
What is a Power on Reset IC?
How to reverse input order?
How to patch glass cuts in a bicycle tire?
Why isn't 'chemically-strengthened glass' made with potassium carbonate to begin with?
Is it legal to meet with potential future employers in the UK, whilst visiting from the USA
What could a self-sustaining lunar colony slowly lose that would ultimately prove fatal?
Popcorn is the only acceptable snack to consume while watching a movie
Can I connect my older mathematica front-end to the free wolfram engine?
Why were helmets and other body armour not commonplace in the 1800s?
Efficient Algorithm for the boundary of a set of tiles
How to ignore kerning of underbrace in math mode
tkinter canvas not drawing top and left lines
ttk tkinter multiple frames/windowsSize limitations of Tkinter grid managerHow to clear Tkinter Canvas?Drawing Labels on a Canvas using TkinterDrawing a image to a tkinter canvasIs there a way of drawing non-canvas lines in Tkinter?TkInter Frame doesn't load if another function is calledPython Multiprocessing Drawing to Tkinter CanvasIn python, with tkinter canvas, is there a way to draw an infinite line?Tkinter inserts separating space between two widgets(canvases)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm trying to draw a grid with tkinter canvas. The logic is fairly simple: for each node in the grid, I draw a rectangle using its top-left and bottom-right corners [code below].
The problem is that tkinter doesn't render the left and top borders of nodes in the first column and row respectively. It's like tkinter is offsetting the canvas by some small # of pixels. Is there a config to correct this? My current workaround is to subtract some small value from cellW
and cellH
, then offset every node's x1
and y1
...this is very hacky.
I am not doing anything weird, just a simple canvas on a root window.
import tkinter as tk
winH = 400
winW = 400
ncols = 10
nrows = 10
cellW = winW / ncols
cellH = winH / nrows
class Node:
def __init__(self, row, col):
self.row = row
self.col = col
return
def generatGrid(nrows, ncols):
grid = []
for r in range(nrows):
row = [ Node(r, c) for c in range(ncols) ]
grid.append(row)
return grid
def drawNode(canvas, node):
x1 = cellW * node.col
y1 = cellH * node.row
x2 = x1 + cellW
y2 = y1 + cellH
canvas.create_rectangle(x1, y1, x2, y2)
return
def drawGrid(canvas, grid):
for row in grid:
for node in row:
drawNode(canvas, node)
return
window = tk.Tk()
canvas = tk.Canvas(window, width=winW, height=winH)
canvas.pack()
grid = generatGrid(nrows, ncols)
drawGrid(canvas, grid)
window.mainloop()
tkinter tkinter-canvas
add a comment |
I'm trying to draw a grid with tkinter canvas. The logic is fairly simple: for each node in the grid, I draw a rectangle using its top-left and bottom-right corners [code below].
The problem is that tkinter doesn't render the left and top borders of nodes in the first column and row respectively. It's like tkinter is offsetting the canvas by some small # of pixels. Is there a config to correct this? My current workaround is to subtract some small value from cellW
and cellH
, then offset every node's x1
and y1
...this is very hacky.
I am not doing anything weird, just a simple canvas on a root window.
import tkinter as tk
winH = 400
winW = 400
ncols = 10
nrows = 10
cellW = winW / ncols
cellH = winH / nrows
class Node:
def __init__(self, row, col):
self.row = row
self.col = col
return
def generatGrid(nrows, ncols):
grid = []
for r in range(nrows):
row = [ Node(r, c) for c in range(ncols) ]
grid.append(row)
return grid
def drawNode(canvas, node):
x1 = cellW * node.col
y1 = cellH * node.row
x2 = x1 + cellW
y2 = y1 + cellH
canvas.create_rectangle(x1, y1, x2, y2)
return
def drawGrid(canvas, grid):
for row in grid:
for node in row:
drawNode(canvas, node)
return
window = tk.Tk()
canvas = tk.Canvas(window, width=winW, height=winH)
canvas.pack()
grid = generatGrid(nrows, ncols)
drawGrid(canvas, grid)
window.mainloop()
tkinter tkinter-canvas
1
Please provide a minimal reproducible example - your code is missing some important parts which prevent us from running your code.
– Bryan Oakley
Mar 25 at 14:26
@BryanOakley, I've updated the code. Thanks.
– eyeezzi
Mar 25 at 20:39
add a comment |
I'm trying to draw a grid with tkinter canvas. The logic is fairly simple: for each node in the grid, I draw a rectangle using its top-left and bottom-right corners [code below].
The problem is that tkinter doesn't render the left and top borders of nodes in the first column and row respectively. It's like tkinter is offsetting the canvas by some small # of pixels. Is there a config to correct this? My current workaround is to subtract some small value from cellW
and cellH
, then offset every node's x1
and y1
...this is very hacky.
I am not doing anything weird, just a simple canvas on a root window.
import tkinter as tk
winH = 400
winW = 400
ncols = 10
nrows = 10
cellW = winW / ncols
cellH = winH / nrows
class Node:
def __init__(self, row, col):
self.row = row
self.col = col
return
def generatGrid(nrows, ncols):
grid = []
for r in range(nrows):
row = [ Node(r, c) for c in range(ncols) ]
grid.append(row)
return grid
def drawNode(canvas, node):
x1 = cellW * node.col
y1 = cellH * node.row
x2 = x1 + cellW
y2 = y1 + cellH
canvas.create_rectangle(x1, y1, x2, y2)
return
def drawGrid(canvas, grid):
for row in grid:
for node in row:
drawNode(canvas, node)
return
window = tk.Tk()
canvas = tk.Canvas(window, width=winW, height=winH)
canvas.pack()
grid = generatGrid(nrows, ncols)
drawGrid(canvas, grid)
window.mainloop()
tkinter tkinter-canvas
I'm trying to draw a grid with tkinter canvas. The logic is fairly simple: for each node in the grid, I draw a rectangle using its top-left and bottom-right corners [code below].
The problem is that tkinter doesn't render the left and top borders of nodes in the first column and row respectively. It's like tkinter is offsetting the canvas by some small # of pixels. Is there a config to correct this? My current workaround is to subtract some small value from cellW
and cellH
, then offset every node's x1
and y1
...this is very hacky.
I am not doing anything weird, just a simple canvas on a root window.
import tkinter as tk
winH = 400
winW = 400
ncols = 10
nrows = 10
cellW = winW / ncols
cellH = winH / nrows
class Node:
def __init__(self, row, col):
self.row = row
self.col = col
return
def generatGrid(nrows, ncols):
grid = []
for r in range(nrows):
row = [ Node(r, c) for c in range(ncols) ]
grid.append(row)
return grid
def drawNode(canvas, node):
x1 = cellW * node.col
y1 = cellH * node.row
x2 = x1 + cellW
y2 = y1 + cellH
canvas.create_rectangle(x1, y1, x2, y2)
return
def drawGrid(canvas, grid):
for row in grid:
for node in row:
drawNode(canvas, node)
return
window = tk.Tk()
canvas = tk.Canvas(window, width=winW, height=winH)
canvas.pack()
grid = generatGrid(nrows, ncols)
drawGrid(canvas, grid)
window.mainloop()
tkinter tkinter-canvas
tkinter tkinter-canvas
edited Mar 25 at 20:38
eyeezzi
asked Mar 24 at 2:31
eyeezzieyeezzi
418313
418313
1
Please provide a minimal reproducible example - your code is missing some important parts which prevent us from running your code.
– Bryan Oakley
Mar 25 at 14:26
@BryanOakley, I've updated the code. Thanks.
– eyeezzi
Mar 25 at 20:39
add a comment |
1
Please provide a minimal reproducible example - your code is missing some important parts which prevent us from running your code.
– Bryan Oakley
Mar 25 at 14:26
@BryanOakley, I've updated the code. Thanks.
– eyeezzi
Mar 25 at 20:39
1
1
Please provide a minimal reproducible example - your code is missing some important parts which prevent us from running your code.
– Bryan Oakley
Mar 25 at 14:26
Please provide a minimal reproducible example - your code is missing some important parts which prevent us from running your code.
– Bryan Oakley
Mar 25 at 14:26
@BryanOakley, I've updated the code. Thanks.
– eyeezzi
Mar 25 at 20:39
@BryanOakley, I've updated the code. Thanks.
– eyeezzi
Mar 25 at 20:39
add a comment |
1 Answer
1
active
oldest
votes
One of the things I find annoying about the canvas is that the border is part of the coordinate space. When you draw a line on the left edge, it gets obscured by the border.
Is there a config to correct this?
Yes.
You can get around this by completely turning off the attributes related to the border:
canvas = tk.Canvas(window, width=winW, height=winH,
borderwidth=0, highlightthickness=0)
If you want to have some sort of border around the canvas, you can place the canvas in a frame, and use the frame to draw the border.
That's an obscure but effective workaround. Much thanks.
– eyeezzi
Mar 25 at 23:44
@eyeezzi: I agree. <shrug>
– Bryan Oakley
Mar 26 at 0:20
Why use the tk attribute attk.Canvas
@BryanOakley
– user11093202
Mar 26 at 0:41
@Programmer: because that's how it was imported in the original question.
– Bryan Oakley
Mar 26 at 0:59
OK @BryanOakley I didn't see that in the main program. My mistake.
– user11093202
Mar 26 at 1:00
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320249%2ftkinter-canvas-not-drawing-top-and-left-lines%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
One of the things I find annoying about the canvas is that the border is part of the coordinate space. When you draw a line on the left edge, it gets obscured by the border.
Is there a config to correct this?
Yes.
You can get around this by completely turning off the attributes related to the border:
canvas = tk.Canvas(window, width=winW, height=winH,
borderwidth=0, highlightthickness=0)
If you want to have some sort of border around the canvas, you can place the canvas in a frame, and use the frame to draw the border.
That's an obscure but effective workaround. Much thanks.
– eyeezzi
Mar 25 at 23:44
@eyeezzi: I agree. <shrug>
– Bryan Oakley
Mar 26 at 0:20
Why use the tk attribute attk.Canvas
@BryanOakley
– user11093202
Mar 26 at 0:41
@Programmer: because that's how it was imported in the original question.
– Bryan Oakley
Mar 26 at 0:59
OK @BryanOakley I didn't see that in the main program. My mistake.
– user11093202
Mar 26 at 1:00
add a comment |
One of the things I find annoying about the canvas is that the border is part of the coordinate space. When you draw a line on the left edge, it gets obscured by the border.
Is there a config to correct this?
Yes.
You can get around this by completely turning off the attributes related to the border:
canvas = tk.Canvas(window, width=winW, height=winH,
borderwidth=0, highlightthickness=0)
If you want to have some sort of border around the canvas, you can place the canvas in a frame, and use the frame to draw the border.
That's an obscure but effective workaround. Much thanks.
– eyeezzi
Mar 25 at 23:44
@eyeezzi: I agree. <shrug>
– Bryan Oakley
Mar 26 at 0:20
Why use the tk attribute attk.Canvas
@BryanOakley
– user11093202
Mar 26 at 0:41
@Programmer: because that's how it was imported in the original question.
– Bryan Oakley
Mar 26 at 0:59
OK @BryanOakley I didn't see that in the main program. My mistake.
– user11093202
Mar 26 at 1:00
add a comment |
One of the things I find annoying about the canvas is that the border is part of the coordinate space. When you draw a line on the left edge, it gets obscured by the border.
Is there a config to correct this?
Yes.
You can get around this by completely turning off the attributes related to the border:
canvas = tk.Canvas(window, width=winW, height=winH,
borderwidth=0, highlightthickness=0)
If you want to have some sort of border around the canvas, you can place the canvas in a frame, and use the frame to draw the border.
One of the things I find annoying about the canvas is that the border is part of the coordinate space. When you draw a line on the left edge, it gets obscured by the border.
Is there a config to correct this?
Yes.
You can get around this by completely turning off the attributes related to the border:
canvas = tk.Canvas(window, width=winW, height=winH,
borderwidth=0, highlightthickness=0)
If you want to have some sort of border around the canvas, you can place the canvas in a frame, and use the frame to draw the border.
answered Mar 25 at 21:41
Bryan OakleyBryan Oakley
226k22287445
226k22287445
That's an obscure but effective workaround. Much thanks.
– eyeezzi
Mar 25 at 23:44
@eyeezzi: I agree. <shrug>
– Bryan Oakley
Mar 26 at 0:20
Why use the tk attribute attk.Canvas
@BryanOakley
– user11093202
Mar 26 at 0:41
@Programmer: because that's how it was imported in the original question.
– Bryan Oakley
Mar 26 at 0:59
OK @BryanOakley I didn't see that in the main program. My mistake.
– user11093202
Mar 26 at 1:00
add a comment |
That's an obscure but effective workaround. Much thanks.
– eyeezzi
Mar 25 at 23:44
@eyeezzi: I agree. <shrug>
– Bryan Oakley
Mar 26 at 0:20
Why use the tk attribute attk.Canvas
@BryanOakley
– user11093202
Mar 26 at 0:41
@Programmer: because that's how it was imported in the original question.
– Bryan Oakley
Mar 26 at 0:59
OK @BryanOakley I didn't see that in the main program. My mistake.
– user11093202
Mar 26 at 1:00
That's an obscure but effective workaround. Much thanks.
– eyeezzi
Mar 25 at 23:44
That's an obscure but effective workaround. Much thanks.
– eyeezzi
Mar 25 at 23:44
@eyeezzi: I agree. <shrug>
– Bryan Oakley
Mar 26 at 0:20
@eyeezzi: I agree. <shrug>
– Bryan Oakley
Mar 26 at 0:20
Why use the tk attribute at
tk.Canvas
@BryanOakley– user11093202
Mar 26 at 0:41
Why use the tk attribute at
tk.Canvas
@BryanOakley– user11093202
Mar 26 at 0:41
@Programmer: because that's how it was imported in the original question.
– Bryan Oakley
Mar 26 at 0:59
@Programmer: because that's how it was imported in the original question.
– Bryan Oakley
Mar 26 at 0:59
OK @BryanOakley I didn't see that in the main program. My mistake.
– user11093202
Mar 26 at 1:00
OK @BryanOakley I didn't see that in the main program. My mistake.
– user11093202
Mar 26 at 1:00
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320249%2ftkinter-canvas-not-drawing-top-and-left-lines%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Please provide a minimal reproducible example - your code is missing some important parts which prevent us from running your code.
– Bryan Oakley
Mar 25 at 14:26
@BryanOakley, I've updated the code. Thanks.
– eyeezzi
Mar 25 at 20:39