gpt4 book ai didi

Python Tkinter : TypeError: 'Frame' object is not callable

转载 作者:行者123 更新时间:2023-11-30 23:25:55 24 4
gpt4 key购买 nike

我创建了一个带有框架的 gui 程序,可以从一个页面移动到另一个页面,并且仅使用方法就可以让它工作,但是一旦我引入一个类,我就会收到以下错误:

类型错误:“框架”对象不可调用

我使用的代码如下:

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 = '黑色')

但这给了我以下回溯:

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"

有人有任何想法可以纠正我所犯的编程错误吗?

最佳答案

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 中所述。发布。

关于Python Tkinter : TypeError: 'Frame' object is not callable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22760882/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com