【发布时间】:2021-05-24 09:30:15
【问题描述】:
我刚刚开始练习 Oops 概念。我正在观看简单的 Oops 视频并尝试将应用步骤应用于 tkinter 问题。我不知道为什么会收到此错误。
from tkinter import *
from tkinter import font as tkFont
top = Tk()
top.minsize(width=1280,height=720)
top.maxsize(width=721,height=521)
class Framesone:
def __init__(self, x1, y1, frame1, text1, x2, y2):
self.stframe = LabelFrame(top, width=300, height=200, highlightcolor="grey", bd=5)
self.stframe.place(x=x1, y=y1)
self.label1 = Label(frame1, text=text1)
self.label1.config(font=("Times", "25", "bold", "italic"))
self.label1.place(x=x2, y=y2)
Framesone(100,200,Framesone().stframe,"HI",20,30)
top.mainloop()
输出
Traceback (most recent call last):
File "E:/python projects my/Basic Programs/MQC FIt Software.py", line 14, in <module>
Framesone(100,200,Framesone().stframe,"HI",20,30)
TypeError: __init__() missing 6 required positional arguments: 'x1', 'y1', 'frame1', 'text1', 'x2', and 'y2'
Process finished with exit code 1
【问题讨论】:
-
当您使用:
Framesone().stframe时,您首先调用Framesone(),不带任何参数,但它需要 6 个参数。 -
另外我想知道为什么您要生成
Framesone对象而不保留它。似乎您正在使用对象初始化,就好像它是一个函数一样。