Problem with geometry pack and grid (tkinter)

1

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

First follow 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 do not know how to solve it. The relevant error is:

tkinter.TclError: can not use geometry manager grid inside. which already has slaves managed by pack

Can anyone help me?

    
asked by anonymous 02.06.2018 / 02:10

1 answer

0

According to documentation (under Warning ), you can not use the grid and pack layout managers together, in the same window as master ).

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

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

However, you may have to reposition all other window elements with 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 Entry and the width parameter were missing:

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

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

principal.mainloop()
    
02.06.2018 / 04:15