Python GUI tutorial geometry manager error

0 arjun menon · September 16, 2015
Python GUI with Tkinter - 4 - the Grid Layout


from Tkinter import *

root = Tk()

topframe = Frame(root)
topframe.pack()
bottomframe = Frame(root)
bottomframe.pack(side=BOTTOM)

button1 = Button(topframe, text = "Button1", fg = "#000")
button2 = Button(topframe, text = "Button2", fg = "#BBE503")
button3 = Button(topframe, text = "Button3", fg = "red")
button4 = Button(bottomframe, text = "Button4", fg = "red")

button1.pack(side = LEFT)
button2.pack(side = LEFT)
button3.pack(side = LEFT)
button4.pack()

name = Label(topframe, text = "Name")
pwd = Label(topframe, text = "Password")

entry1 = Entry(topframe)
entry2 = Entry(topframe)

name.grid(row = 0)
pwd.grid(row = 1)

entry1.grid(row = 0, column = 1)
entry2.grid(row = 1, column = 1)

root.mainloop()

If I run this, I get this error


Traceback (most recent call last):
  File "/home/arjun/Desktop/window.py", line 26, in
    name.grid(row = 0)
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1985, in grid_configure
    + self._options(cnf, kw))
_tkinter.TclError: cannot use geometry manager grid inside .3072634732L which already has slaves managed by pack
[Finished in 1.6s with exit code 1]
[shell_cmd: python -u "/home/arjun/Desktop/window.py"]
[dir: /home/arjun/Desktop]
[path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/arjun/.rvm/bin]

What does that "geometry manager running slaves as pack actually means"

Ofcourse by removing the button code, it ran just fine.

Post a Reply

Replies

Oldest  Newest  Rating
0 sfolje 0 · September 18, 2015
If somepack owns a slave, you cannot own it at the same time. You buy it or leave it. Grid or pack. Slaves are managed by packs so they cannot be managed by grid. Exclusive or XOR.
  • 1

Python

107,028 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator