1

Using Tkinter I have a Toplevel named self.edit_window, a Frame named frame and a Canvas named canvas. All I want to do is add the frame to the canvas, which I try to do by using the create_window method:

#make canvas
canvas = Tkinter.Canvas(self.edit_window) 

#make frame and add to canvas
frame = Tkinter.Frame()
canvas.create_window(0,0, anchor = Tkconstants.NW, window = frame, width = 200, height = 200)

And I get the following error on the create_window call:

TclError: can't use .173048428 in a window item of this canvas

And I have no idea what that means. Any ideas?

3
  • Did you try anchor = NW? Commented Jan 20, 2012 at 18:25
  • Yes I did, the way I imported I have to add the Tkconstants to it. Commented Jan 20, 2012 at 18:26
  • anchor has nothing to do with this problem. Commented Jan 20, 2012 at 18:34

1 Answer 1

1

The code you supply does not give this error. Are you certain that code is enough to illustrate the problem?

That being said, the error you say you are getting is consistent with trying to add to a canvas a window that is not a sibling or child of the canvas. According to the official tk documentation:

The window specified by pathName must either be a child of the canvas widget or a child of some ancestor of the canvas widget. PathName may not refer to a top-level window.

If you make your frame a child of the canvas, this problem will go away (though, strictly speaking, it doesn't have to be an immediate child).

Sign up to request clarification or add additional context in comments.

1 Comment

This latter part answers it. As I said self.edit_window is a Tkinter.Toplevel. Since I did not specify any parent for the frame, self.edit_window is not an ancestor of frame. But I did specify the canvas as a child of self.edit_window. If I declare frame as: frame = Tkinter.Frame(self.edit_window), then now both frame and canvas have a common ancestor. Also note that if I declare canvas as canvas = Tkinter.Canvas(root) where root is my main window, then it also works because the frame defaulted to a child of root since I did not pass it a parent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.