-2

I want button 1 on to the second frame

enter image description here

from tkinter import *

root =Tk()

class Graphic():
    def __init__(self, master):
        self.colour = "blue"

        self.frame_input = Frame(master, height =100, width=100, bg="green").grid(row=0, column=0)
        self.label_process = Label(master, width=30).grid(row=1, column=0)
        self.frame_button = Frame(master,height=100,width=100, bg="red").grid(row=2, column=0)
        self.button = Button(master, text="1", bg=self.colour).grid(row=0, column=0)


if '__main__'  == __name__:

    grafic = Graphic(root)
    root.mainloop()
ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
Student
  • 1
  • 1
  • Where is the point to create frames and never use them? Do you want `frame_button` as master to your Button? – Thingamabobs Nov 19 '21 at 15:22
  • 1
    I rolled back your question to show the original code; updating the question to ask a brand new question in response to answers invalidates the answers (I did edit the answer to address both problems). – ShadowRanger Nov 19 '21 at 15:34

1 Answers1

2

The first argument for each widget is the parent to attach to. You told it to attach to master, and it did. If you want it attached to the second frame, change:

self.button = Button(master, text="1", bg=self.colour).grid(row=0, column=0)

to:

self.button = Button(self.frame_button, text="1", bg=self.colour)
self.button.grid(row=0, column=0)

Note, this still doesn't work, because you tried to chain your grid calls, and grid returns None, so all your attributes (including self.frame_button) are None, not widgets. To fix, split the creation and layout steps for all your widgets:

self.frame_input = Frame(master, height =100, width=100, bg="green")
self.frame_input.grid(row=0, column=0)

self.label_process = Label(master, width=30)
self.label_process.grid(row=1, column=0)

self.frame_button = Frame(master,height=100,width=100, bg="red")
self.frame_button.grid(row=2, column=0)

self.button = Button(self.frame_button, text="1", bg=self.colour)
self.button.grid(row=0, column=0)
ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
  • Thank's for Help sir – Student Nov 19 '21 at 18:15
  • @Student: You're welcome. If this answered your question adequately, please click the check box on the left side of the answer (near the voting arrows) to mark it as accepted (it helps others know the problem is fully resolved, and hey, bonus rep for both you and me is a nice side-benefit). – ShadowRanger Nov 19 '21 at 18:20