Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tkinter:TypeError:';框架';对象不可调用_Python_Tkinter_Ttk - Fatal编程技术网

Python Tkinter:TypeError:';框架';对象不可调用

Python Tkinter:TypeError:';框架';对象不可调用,python,tkinter,ttk,Python,Tkinter,Ttk,我创建了一个gui程序,其中的框架可以从一个页面移动到另一个页面,并且在仅使用方法的情况下可以正常工作,但一旦引入一个类,就会出现以下错误: TypeError:“Frame”对象不可调用 我使用的代码如下: import sys from tkinter import * from tkinter import ttk class teachingContent(Tk): def __init__(self): super(teachingContent, self

我创建了一个gui程序,其中的框架可以从一个页面移动到另一个页面,并且在仅使用方法的情况下可以正常工作,但一旦引入一个类,就会出现以下错误:

TypeError:“Frame”对象不可调用

我使用的代码如下:

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()
我对此行中的代码进行了更改,添加了
。按如下方式配置

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()
self.first\u title\u frame.configure(self,height=title\u 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"
回溯(最近一次呼叫最后一次):
文件“C:\Users\Tete De Bite\Dropbox\Year3\FinalYearProject\pythonTutoringSystem\debug.py”,第47行,在
tc.formSize()
文件“C:\Users\Tete De Bite\Dropbox\Year3\FinalYearProject\pythonTutoringSystem\debug.py”,第31行,formSize
self.first\u title\u frame.configure(self,height=title\u height,bg='black')
文件“C:\Python33\lib\tkinter\\uuuu init\uuuuu.py”,第1263行,在configure中
返回自。_配置('configure',cnf,kw)
文件“C:\Python33\lib\tkinter\\ uuuuu init\ uuuuuu.py”,第1254行,在\u configure中
self.tk.call(_flatten((self._w,cmd))+self._选项(cnf))
_tkinter.TclError:未知选项“-pady”
有人有什么想法可以纠正我犯的编程错误吗

self.first_title_frame.configure(self, height=title_height, bg = 'black')
这里不需要将
self
作为参数传递

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

无论如何,
ttk.Frame
s似乎不允许您直接配置它们的背景色<代码>bg
未列在“标准选项”或“小部件特定选项”下。尝试使用
样式
参数,如后文所述。

好的,我尝试删除self,但仍然得到完全相同的错误。它仍然说
未知选项“-pady”
,还是其他什么?它说
未知选项“-bg”
对,因为
bg
不是ttk帧的有效属性。我编辑了我的帖子来讨论这个问题。