2014-03-31 149 views
1

我創建了一個GUI程序,可以在頁面之間移動,並且只在使用方法時能夠工作,但只要我引入一個類,就可以獲得以下內容錯誤:Python Tkinter:TypeError:'Frame'對象不可調用

TypeError: 'Frame' object is not callable

我使用的代碼如下:

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() 

我進行了更改代碼在這一行加入.configure如下:

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

,但是這給了我下面的回溯:

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" 

有沒有人有這將糾正編程錯誤,我做任何想法?

回答

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

您不需要在這裏通過self作爲參數。

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

在任何情況下,ttk.Frame小號似乎並沒有讓你直接配置他們的背景顏色。 bg未在「標準選項」或「特定於窗口小部件的選項」下列出here。請嘗試使用style參數,如this後所述。

+0

好吧我試着去除自我,但我仍然得到完全相同的錯誤。 – Tumbler

+0

它仍然會說'未知選項「-pady」',或其他? – Kevin

+0

它說'未知的選項「-bg」' – Tumbler