在我的代码中,函数调用被分配到哪里?为什么会出现错误?

Where is a function call being assigned to in my code? Why is the error presenting itself?

我的代码出错了。它说语法错误:无法分配函数调用。我在 windows 10 上使用 IDLE。这是导致错误的代码:

from tkinter import *
from tkinter.Ttk import *
import sys

root = Tk()

class Label:
    def __init__(self, txt, fomtsize, fomtype, hhexx_fg, borderstate, hhexx_bg_truestate, hhexx_bg, yex_pos, why_pos, bordr, masta, hght, wdth, xp, yp):

        if ((hhexx_bg_truestate == False) and (borderstate == False)):
            Label(master=masta, textvariable=str(txt), font=(float(fomtsize), str(fomtype)), fg=str(hhexx_fg), height=(int(hght)/2), width=(int(wdth)/2)), padx=xp, pady=yp).place(height, width = hght, wdth, x, y = yex_pos, why_pos)
            self.text = txt
            self.size = fomtsize
            self.font = fomtype
            self.color = hhexx_fg
            self.x_position = yex_pos
            self.y_position = why_pos
            self.border = bordr
            self.height = hght
            self.width = wdth

        elif ((hhexx_bg_truestate == True) and (borderstate == False)) :
            Label(bg=hhexx_bg, master=masta, textvariable=str(txt), font=(float(fomtsize), str(fomtype)), fg=str(hhexx_fg), height=(int(hght)/2), width=(int(wdth)/2)), padx=xp, pady=yp).place(height, width = hght, wdth, x, y = yex_pos, why_pos)
            self.text = txt
            self.size = fomtsize
            self.font = fomtype
            self.color = hhexx_fg
            self.x_position = yex_pos
            self.y_position = why_pos
            self.border = bordr
            self.height = hght
            self.width = wdth

        elif ((hhexx_bg_truestate == False) and (borderstate == True)) :
            Label(bd=bordr, master=masta, textvariable=str(txt), font=(float(fomtsize), str(fomtype)), fg=str(hhexx_fg), height=(int(hght)/2), width=(int(wdth)/2)), padx=xp, pady=yp).place(height, width = hght, wdth, x, y = yex_pos, why_pos)
            self.text = txt
            self.size = fomtsize
            self.font = fomtype
            self.color = hhexx_fg
            self.x_position = yex_pos
            self.y_position = why_pos
            self.border = bordr
            self.height = hght
            self.width = wdth

        elif ((hhexx_bg_truestate == True) and (borderstate == True)) :
            Label(bg=hhexx_bg, bd=bordr, master=masta, textvariable=str(txt), font=(float(fomtsize), str(fomtype)), fg=str(hhexx_fg), height=(int(hght)/2), width=(int(wdth)/2)), padx=xp, pady=yp).place(height, width = hght, wdth, x, y = yex_pos, why_pos)
            self.text = txt
            self.size = fomtsize
            self.font = fomtype
            self.color = hhexx_fg
            self.x_position = yex_pos
            self.y_position = why_pos
            self.border = bordr
            self.height = hght
            self.width = wdth

(我知道我可以改进 class 的编码方式,我浪费了很多行而且我没有使用最佳实践。)

在这段代码中,函数调用在哪里分配给任何东西?之前我在 class:

中写过
self.label = Label(...)

我能理解错误了。我正在将标签功能分配给某物。但是这一次,我纠正了这一点!为什么会出现错误?

您必须擦除 ) 宽度。

所以正确的字符串是这样的:

Label(master=masta, textvariable=str(txt), font=(float(fomtsize), str(fomtype)), fg=str(hhexx_fg), height=(int(hght)/2), width=(int(wdth)/2), padx=xp, pady=yp).place(height, width = hght, wdth, x, y = yex_pos, why_pos)

您还必须重命名 class 因为 Label 已被 tkinter 使用。

use import tkinter as tk then tk.Label() - JacksonPro

最后你必须看看你的 <a href="https://www.tutorialspoint.com/python/tk_place.htm" rel="nofollow noreferrer">.place()</a> 方法。我不确定哪个参数有什么价值,所以你必须更正这个。