0

I am trying to put a frame inside another frame in tkinter. Can someone explain why it isn't working? I am just starting to learn Tkinter.

from tkinter import *
from PIL import *
if __name__=="__main__":
  root = Tk()
  root.title("Sales")
  root.geometry("1440x855")
  root.resizable(0, 0)
  Label(root, text = 'Tax Invoice').pack(side = TOP, pady = 6)
  frame1 = Frame(root,bg="black",width=1400,height=780).pack()
  frame2 = Frame(frame1,bg="green",width=100,height=100).pack()
  top.mainloop()
Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52
AMI
  • 1
  • 1
    `frame1` is always `None` not a `tkinter.Frame` object. For more info read [this](https://stackoverflow.com/a/66385069/11106801) – TheLizzard Apr 24 '21 at 17:15
  • change `frame1 = Frame(root,bg="black",width=1400,height=780).pack()` to `frame1 = Frame(root,bg="black",width=1400,height=780)` and `frame1.pack()` – TheLizzard Apr 24 '21 at 17:15
  • 1st u need to change `top.mainloop()` change to `root.mainloop()` small spelling mistakes make big errors sometimes Case sensitive and spelling create problems in our code – Ramesh Apr 24 '21 at 17:30
  • What is "the error"? Is there any error message you can add to the question? – Nico Haase Apr 24 '21 at 17:54
  • Please don't tag code questions with Editor/IDE, which has nothing to do with code errors. – Terry Jan Reedy Apr 25 '21 at 03:56

1 Answers1

1

Try this:

import tkinter as tk

if __name__ == "__main__":
    root = Tk()
    root.title("Sales")
    root.geometry("1440x855")
    root.resizable(False, False)

    label = tk.Label(root, text="Tax Invoice")
    label.pack(side="top", pady=6)

    frame1 = Frame(root, bg="black", width=1400, height=780)
    frame1.pack()
    frame2 = Frame(frame1, bg="green", width=100, height=100)
    frame2.pack()

    root.mainloop()

Basically applying what @Ramesh and I said in the comments.

TheLizzard
  • 7,248
  • 2
  • 11
  • 31
  • I tried this code and it gave an error which was that the first frame did not appear on the screen. – AMI Apr 25 '21 at 18:07
  • @AMI Does the second frame appear on the screen? – TheLizzard Apr 25 '21 at 18:11
  • Yes it does. But only the second frame appears. – AMI Apr 26 '21 at 19:19
  • @AMI my guess is that the first frame resizes to fit all of its child widgets (the second frame) and that is why you don't see it. Try adding `frame1.pack_propagate(False)` if you are still using `pack` inside it. – TheLizzard Apr 26 '21 at 19:36