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

2024-07-04 17:06:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我的代码导致了一个错误。它表示syntaxerror:无法分配函数调用。我正在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

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

在代码中,函数调用被分配到哪里?以前我在课堂上写过:

self.label = Label(...)

那我就能理解错误了。我正在给某个东西分配标签函数。但这一次,我纠正了这一点!为什么会出现错误


Tags: posselftxtwidthbgheightstrfg
1条回答
网友
1楼 · 发布于 2024-07-04 17:06:56

您必须擦除宽度处的)

因此正确的字符串如下所示:

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)

您还必须重命名类,因为tkinter已经使用了Label

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

最后你必须看看你的.place()方法。我不确定哪个参数的值,所以你必须纠正这个问题

相关问题 更多 >

    热门问题