FAQ

Tim Shannon wrote:
I'm new to python, so keep that in mind.

I have a tk Canvas that I'm trying to draw on, and I want to start my
drawing at an offset (from 0) location. So I can tweak this as I
code, I set this offset as a class level variable:

def ClassName:
OFFSET = 20

def __init__(self, master)):
self.canvas = Canvas(master)
self.canvas.create_rectangle(self.OFFSET,
self.OFFSET,
300 + self.OFFSET,
300 + self.OFFSET,
width=2)


The weird thing is, it doesn't offset. If I set my offset to 100000,
it still starts drawing at 0,0.
Here's the really weird part (at least to me), if I put a print line
right about my drawing statements to print the value of the offset, it
works like it should, and offsets the drawing.
If I remove the print line, the offset goes away.

This makes no sense to me.
Tim Shannon wrote:
I'm new to python, so keep that in mind.

I have a tk Canvas that I'm trying to draw on, and I want to start my
drawing at an offset (from 0) location. So I can tweak this as I
code, I set this offset as a class level variable:

def ClassName:
OFFSET = 20

def __init__(self, master)):
self.canvas = Canvas(master)
self.canvas.create_rectangle(self.OFFSET,
self.OFFSET,
300 + self.OFFSET,
300 + self.OFFSET,
width=2)
The above code wouldn't even compile. Please be careful to cut-and-paste
working code into your email message. (I've made this mistake myself!)
Changes to make:

1. first line: change "def" to "class"

2. def __init__(self, master)): <--- get rid of extra ")"

3. Make sure to "pack" the canvas into the overall Tk window:

self.canvas = Canvas(master)
self.canvas.pack() <--- add this line

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 3 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedApr 6, '09 at 7:37p
activeApr 7, '09 at 1:47p
posts3
users2
websitepython.org

2 users in discussion

Tim Shannon: 2 posts John Posner: 1 post

People

Translate

site design / logo © 2022 Grokbase