5

我正在尝试放置在 aLabelFrame中显示的LabelaCanvas但是我收到此错误:

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

这是我的代码:

from Tkinter import LabelFrame, Label, Tk, Canvas

root = Tk()

canvas = Canvas(root)
canvas.pack()

label_frame = LabelFrame(text="I'm a Label frame")
label = Label(label_frame,text="Hey I'm a Label")

canvas.create_window(10,20,window=label)

root.mainloop()
4

1 回答 1

3

制作 的label_frame孩子,并在框架内canvas打包。label然后将label_frame(而不是label)传递给create_window.

...
label_frame = LabelFrame(canvas, text="I'm a Label frame")
label = Label(label_frame, text="Hey I'm a Label")
label.pack()

canvas.create_window(10, 20, window=label_frame, anchor='w')
...

anchorCENTER默认情况下。要正确对齐,请将锚指定为w

于 2013-10-26T10:10:32.730 回答