0

I tried to write this code but I face the problem of grid and pack I suppose, down below I have posted also the error, you can check

    from tkinter import *
    import csv

    import os
    os.chdir(r"C:\Users\Umer Selmani\Desktop\prog.practice\MP1")

    class Diet:
        def __init__(self,name):

            self.name = name
            name.title("Cafeteria")

            self.label_1=Label(name,text="Sehir Cafeteria", font="ariel 13 bold italic", fg="red",height="5", bg="darkblue").pack(fill=X)
            self.stradio=Radiobutton(name,text="1300").grid(row=2,column=1)
            self.ndradio=Radiobutton(name,text="1700").grid(row=2,column=2)
            self.rdradio=Radiobutton(name,text="2100").grid(row=2,column=3)




    main=Tk()
    my_gui=Diet(main)
    main.mainloop()

Here I have an error that pops up when I try to run the code, can you please give me explanation, why something like this happens.

 Traceback (most recent call last):
      File "C:/Users/Umer Selmani/.PyCharmEdu2018.2/config/scratches/scratch.py", line 22, in <module>
        my_gui=Diet(main)
      File "C:/Users/Umer Selmani/.PyCharmEdu2018.2/config/scratches/scratch.py", line 14, in __init__
        self.stradio=Radiobutton(name,text="1300").grid(row=2,column=1)
      File "C:\Program Files\Python37\lib\tkinter\__init__.py", line 2223, in grid_configure
        + self._options(cnf, kw))
    _tkinter.TclError: cannot use geometry manager grid inside . which already has slaves managed by pack  

Thank you, I appreciate you help.
With respect Umer Selmani

Nouman
  • 6,947
  • 7
  • 32
  • 60

1 Answers1

0

You can't mix grid and pack with widgets that have the same parent.

Why? As grid will try to lay out widgets, perhaps increasing or decreasing widgets according to different options. Then pack will try to do the same according to its rules. This may require changing the width or height of the widget.

(See this answer)

Each of these geometric managers has its own specific behavior. They cannot be used together within the same parent widget

fedotsoldier
  • 190
  • 1
  • 16