-1

Here is the SS of code with error

Error: _tkinter.TclError: cannot use geometry manager grid inside . which already has slaves managed by pack

When i change to

user.grid(row=0, column=0)
password.grid(row=1, column=0)

user.pack(row=0, column=0)
password.pack(row=1, column=0)

it is throwing an error:

_tkinter.TclError: bad option "-row": must be -after, -anchor, -before, -expand, -fill, -in, -ipadx, -ipady, -padx, -pady, or -side

SS of Code with Error

MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • 2
    remove the screenshots and provide code and error message in text format – eshirvana Jan 09 '22 at 04:36
  • Screenshots do not allow us to cut and paste to try your code. Paste text as *text*. – Mark Tolonen Jan 09 '22 at 04:41
  • The error suggest exactly what is wrong with your code. `.pack()` simply dosent know the *optional argument* `row`. In addition, it makes little to no sense for you to use the geometry manager *grid* just to switch to *pack*. [You may find this helpful](https://stackoverflow.com/questions/63536505/how-do-i-organize-my-tkinter-appllication/63536506#63536506) – Thingamabobs Jan 09 '22 at 04:45

1 Answers1

0

You can't mix pack and grid.

Warning: Never mix grid and pack in the same master window. Tkinter will happily spend the rest of your lifetime trying to negotiate a solution that both managers are happy with. Instead of waiting, kill the application, and take another look at your code. A common mistake is to use the wrong parent for some of the widgets.

I would say to choose the grid function because it is easier to choose where each widget goes. So, change l1.pack() to l1.grid(row=0, column=0) (Replace the 0's with the row and column you want to place it with).

For example:

from tkinter import *
root = Tk() 
root.geometry("700x400") # Title
root.title("Dance Admission Form") # Label
l1 = Label(text="Admission Form", font="Arial 15 bold")
l1.grid(row=0, column=0) 
user = Label(root, text="Username")
password = Label(root, text="Password")
user.grid(row=1, column=0)
password.grid(row=2, column=0) 
root.mainloop() 

or a centered version:

from tkinter import *
root = Tk() 
root.geometry("700x400") # Title
root.title("Dance Admission Form") # Label
l1 = Label(text="Admission Form", font="Arial 15 bold")
l1.grid(row=0, column=0)
root.columnconfigure(0, weight=1)
user = Label(root, text="Username")
password = Label(root, text="Password")
user.grid(row=1, column=0)
password.grid(row=2, column=0) 
root.mainloop() 
krmogi
  • 2,588
  • 1
  • 10
  • 26
  • But l1 is my Heading of my GUI so how can i place in the middle when i use .pack while packing it will place it in the middle and while using .grid it will placed it by defalt in 0th row – Krunal Dhaygude Jan 09 '22 at 05:11
  • @KrunalDhaygude Take a look at my edited answer. – krmogi Jan 09 '22 at 17:02