i am trying template my tkinter application. But i cant put buttons into my Frames.
Is Frame the right control for use as a template? or is there something different.
from Tkinter import *
root = Tk()
frame = Frame(root, height="200", width="200", bg="green").pack()
b = Button(frame, text="Hell World").pack(padx="10", pady="10")
z = Label(root, text="OUTSIDE").pack()
root.mainloop()
this is my code.
the code runs, but the button is beneath the green frame. But i want to have this button inside of the frame.
Is this possible?
frame = Frame(root, height="200", width="200", bg="green").pack()
After this line executes, frame is equal to None because that's what pack() returns. You need to assign a widget and pack it on separate lines if you want to keep a reference to it.
frame = Frame(root, height="200", width="200", bg="green")
frame.pack()
Same for b and z, but you never use them so they don't matter as much.
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