微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

我的代码导致错误。它说语法错误:无法分配函数调用。我在 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,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,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,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,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(...)

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

解决方法

您必须擦除宽度处的 )

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

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)

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

使用 import tkinter 作为 tk 然后使用 tk.Label() - JacksonPro

最后,您必须查看您的 .place() 方法。我不确定哪个参数有什么价值,所以你必须纠正这个。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。