1

I created a gui program with frames to move from page to page and I got it working while using methods only, but as soon as I introduce a class I get the following Error:

TypeError: 'Frame' object is not callable

The code I am using is as follows:

import sys
from tkinter import *
from tkinter import ttk

class teachingContent(Tk):

    def __init__(self):
        super(teachingContent, self).__init__()

        self.first_title_frame = ttk.Frame()
        self.first_frame = ttk.Frame()

    def nextButtonPressed(self):
        pass

    def prevButtonPressed(self):
        pass

    def formSize(self):
        self.geometry("650x450+200+200") # Sets the size of the gui
        self.title("Python Tutor")

        self.nbutton = Button(text = "Next", command = self.nextButtonPressed).place(x=561,y=418)

        self.pbutton = Button(text = "Previous", command = self.prevButtonPressed).place(x=0,y=418)

        title_height = 40

        self.first_title_frame(self, height=title_height, bg = 'black')
        self.first_title_frame['borderwidth'] = 2
        self.first_title_frame.grid(column=0, row=0, padx=35, pady=5, sticky=(W, N, E))


        self.first_frame(self, bg = 'DarkSlateGray4')
        self.first_frame['borderwidth'] = 2
        self.first_frame['relief'] = 'sunken'
        self.first_frame.grid(column=0, row=0, padx=33, pady=50, sticky=(W, N, E))

        self.label = Label(self.first_title_frame, text = "Welcome to the Tutor").pack()

        self.label = Label(self.first_frame, text = "Welcome to the Python Tutor. In this program you will learn to tools and techniques need to use Python.")
        self.label.grid(column=0, row=0, ipadx=85,pady=11, padx=11, sticky=(N))

tc = teachingContent()
tc.formSize()

I made a change to the code in this line adding .configure as follows:

self.first_title_frame.configure(self, height=title_height, bg = 'black')

but this gives me the following traceback:

Traceback (most recent call last):
  File "C:\Users\Tete De Bite\Dropbox\Year3\FinalYearProject\pythonTutoringSystem\debug.py", line 47, in <module>
   tc.formSize()
  File "C:\Users\Tete De Bite\Dropbox\Year3\FinalYearProject\pythonTutoringSystem\debug.py", line 31, in formSize
    self.first_title_frame.configure(self, height=title_height, bg = 'black')
  File "C:\Python33\lib\tkinter\__init__.py", line 1263, in configure
    return self._configure('configure', cnf, kw)
  File "C:\Python33\lib\tkinter\__init__.py", line 1254, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: unknown option "-pady"

Does anyone have any ideas that will correct the programming mistake I am making?

1 Answer 1

3
self.first_title_frame.configure(self, height=title_height, bg = 'black')

You don't need to pass self as a parameter here.

self.first_title_frame.configure(height=title_height, bg = 'black')

In any case, ttk.Frames don't seem to allow you to directly configure their background colors. bg is not listed here under "standard options" or "widget-specific options". Try using the style argument instead, as described in this post.

Sign up to request clarification or add additional context in comments.

4 Comments

ok I tried removing self but I still get exactly the same error.
Does it still say unknown option "-pady", or something else?
It says unknown option "-bg"
Right, because bg isn't a valid attribute for ttk frames. I've edited my post to discuss that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.