Search code examples
pythontkinterttk

How can I put a ttk.LabelFrame inside a ttk.PanedWindow?


I'm initiating in ttk and I keep getting this error while trying to add a LabelFrame inside a PanedWindow. Happens on line 46 (self.pwEntries.add(self.lfEntries)):

_tkinter.TclError: wrong # args: should be ".!frame.!panedwindow.!panedwindow add window"

As I've no idea how to solve it I would really appreciate some help, please...

My code goes like this:

from tkinter import *
from tkinter import ttk


class CalcVendGame:
    def __init__(self, root):

        root.title("Calcula Venda Games")

        self.mainframe = ttk.Frame(root, padding="3 3 12 12")
        self.mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
        root.columnconfigure(0, weight=1)
        root.rowconfigure(0, weight=1)

        self.pwRoot = ttk.PanedWindow(self.mainframe, orient=VERTICAL)

        self.pwEntries = ttk.PanedWindow(self.pwRoot, orient=HORIZONTAL)

        self.lfEntries = ttk.LabelFrame(self.pwEntries, labelanchor='nw').grid(
            column=0, row=0, sticky=(N, W))

        ttk.Label(self.lfEntries, text="Valor em Dólar de cada cópia:", padding="5").grid(
            column=2, row=1, sticky=E)
        self.CopiaEmDolar = StringVar()
        cpEmDol_entry = ttk.Entry(
            self.lfEntries, width=7, textvariable=self.CopiaEmDolar)
        cpEmDol_entry.grid(column=3, row=1, sticky=W)
        ttk.Label(self.lfEntries, text="Ex: \"19.99\"", padding="5").grid(
            column=4, row=1, sticky=W)

        ttk.Label(self.lfEntries, text="Quantidade de cópias vendidas:", padding="5").grid(
            column=2, row=2, sticky=E)
        self.CopiasVendidas = StringVar()
        cpVend_entry = ttk.Entry(
            self.lfEntries, width=7, textvariable=self.CopiasVendidas)
        cpVend_entry.grid(column=3, row=2, sticky=W)

        ttk.Button(self.lfEntries, text="Calcular").grid(
            column=4, row=3, sticky=W)

        self.pwEntries.add(self.lfEntries)

        self.pwPC = ttk.PanedWindow(self.pwRoot, orient=HORIZONTAL)

        self.pwSteam = ttk.PanedWindow(self.pwPC, orient=VERTICAL)

        self.lfSteam = ttk.LabelFrame(self.pwSteam, padding=(
            5), text='Steam', labelanchor='nw')

        ttk.Label(self.lfSteam, text="Cut 35%", padding="5").grid(
            column=0, row=0, sticky=W)
        ttk.Separator(self.lfSteam, orient=HORIZONTAL)

        self.pwPatreon = ttk.PanedWindow(self.pwRoot, orient=VERTICAL)

        self.pwPC.add(self.pwSteam)
        self.pwPC.add(self.pwPatreon)

        self.pwMobile = ttk.PanedWindow(self.pwRoot, orient=HORIZONTAL)

        # self.pwRoot.add(self.lfEntries)
        self.pwRoot.add(self.pwEntries)
        self.pwRoot.add(self.pwPC)
        self.pwRoot.add(self.pwMobile)

root = Tk()
CalcVendGame(root)
root.mainloop()

Also, this code give me no errors but results on a blank window:

from tkinter import *
from tkinter import ttk

master = Tk()
mainframe = ttk.Frame(master, padding="3 3 10 10")

p = ttk.Panedwindow(mainframe, orient=VERTICAL)

# two panes, each of which would get widgets gridded into it:
f1 = ttk.Labelframe(p, text='Pane1', width=100, height=100)
ttk.Label(f1, text="Valor em Dólar de cada cópia:", padding="5")
f2 = ttk.Labelframe(p, text='Pane2', width=100, height=100)
ttk.Label(f2, text="Quantidade de cópias vendidas:", padding="5")
p.add(f1)
p.add(f2)

master.mainloop()

Solution

  • You forgot to use any layout manager on the widgets. Below is an updated code using pack():

    from tkinter import *
    from tkinter import ttk
    
    master = Tk()
    
    mainframe = ttk.Frame(master, padding="3 3 10 10")
    mainframe.pack()
    
    p = ttk.Panedwindow(mainframe, orient=VERTICAL)
    p.pack()
    
    # two panes, each of which would get widgets gridded into it:
    f1 = ttk.Labelframe(p, text='Pane1', width=100, height=100)
    ttk.Label(f1, text="Valor em Dólar de cada cópia:", padding="5").pack()
    f2 = ttk.Labelframe(p, text='Pane2', width=100, height=100)
    ttk.Label(f2, text="Quantidade de cópias vendidas:", padding="5").pack()
    p.add(f1)
    p.add(f2)
    
    master.mainloop()