I'm trying to place a LabelFrame
which displays a Label
inside a Canvas
however I receive this error:
TclError: can't use .28425672.27896648 in a window item of this canvas
Here's my code:
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()
Make the label_frame
child of the canvas
, and pack the label
inside the frame. Then pass label_frame
(instead of label
) to 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')
...
anchor
is CENTER
by default. To correctly align, specify anchor as w
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With