Problem with Geometry pack and grid (Tkinter)

Asked

Viewed 565 times

1

to tell the truth these two geometries are very complicated, but unfortunately I need to use this 2 in this project. So come on.

first follows the code:

from tkinter import*
from tkinter.ttk import *

class principal:

    def __init__(self):

        principal = Tk()
        principal.geometry("860x540+75+75")
        principal.overrideredirect(True)

        esquerda = PhotoImage(file="altura.png")
        ladoesquerdo = Label(principal, background="WHITE", image=esquerda)
        ladoesquerdo.esquerda = esquerda
        ladoesquerdo.pack(side=LEFT, padx=5)

        cima = PhotoImage(file="largura.png")
        partedecima = Label(principal, background="WHITE", image=cima)
        partedecima.cima = cima
        partedecima.pack(side=TOP)

        baixo = PhotoImage(file="largura.png")
        partedebaixo = Label(principal, background="WHITE", image=baixo)
        partedebaixo.baixo = baixo
        partedebaixo.pack(side=BOTTOM)

        direita = PhotoImage(file="altura.png")
        ladodireito = Label(principal, background="WHITE", image=direita)
        ladodireito.direito = direita
        ladodireito.pack(side=RIGHT, padx=5)

    #:::::::::: CADASTRO ::::::::::::
        framedoscadastros = LabelFrame(principal, height=475, width=400, text="::::::::::::::: Cadastrar :::::::::::::::").pack(side=LEFT)

        nome0 = Label(framedoscadastros, text="Nome:  ").grid(row=0, column=0)
        nome1 = Entry(framedoscadastros, width=20).grid(row=0, column=1)

        sobre0 = Label(framedoscadastros, text="Sobrenome:  ").grid(row=1, column=0)
        sobre1 = Entry(framedoscadastros, width=20).grid(row=1, column=1)

        telefone0 = Label(framedoscadastros, text="Telefone:  ").grid(row=2, column=0)
        telefone1 = (framedoscadastros, width).grid(row=2, column=1)

        nserie0 = Label(framedoscadastros, text="Nº de Série:  ").grid(row=3, column=0)
        nserie1 = Entry(framedoscadastros, width=20).grid(row=3, column=1)

        problema0 = Label(framedoscadastros, text="Problema:  ").grid(row=4, column=0)
        problema1 = Text(framedoscadastros, width=20, height=4).grid(row=4, column=1)

        nome1 = Label(framedoscadastros, text="Nome:  ").grid(row=0, column=0)


    #::::::::::: BUSCAR :::::::::::::
        framedebuscarcadastros = LabelFrame(principal, height=475, width=400, text="::::::::::::::: Buscar Cadastros :::::::::::::::").pack(side=RIGHT)

        principal.mainloop

principal()

My code is as clear as it could be, the problem is also very clear, but I don’t know how to fix it. The pertinent error is:

Tkinter.Tclerror: cannot use Geometry manager grid Inside . which already has Slaves Managed by pack

someone can help me?

1 answer

1

Cannot use layout managers grid and pack together, in the same window master.

One possibility to correct is, for example, to remove the command pack() at the end of the line, at the point where the frame framedoscadastros:

framedoscadastros = LabelFrame(principal, height=475, width=400, text="::::::::::::::: Cadastrar :::::::::::::::")

However, you may need to reposition all other window elements with the grid.

If you need a different layout and the problem persists, try designing this layout using only one type of manager (or grid or pack).

Other problems in the code are:

When instantiating telefone1, the class name was missing Entry and the parameter width:

telefone1 = Entry(framedoscadastros, width=20).grid(row=2, column=1)

And in calling the method mainloop, the parentheses were missing:

principal.mainloop()
  • This is the question of documenting the whole code with one manager only. Because honestly 'grid' is very boring, but quite useful. I tried to put the grid’s inside a 'Label' only it didn’t work out so well.

  • Another possibility is to use the place. Although some people find it more complicated than the grid, maybe he can help you in this case

  • truth, for me it has no problem, but wanted so much that the grid' help in this case

  • the management with the place didn’t work either.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.