python - 在我的代码中分配函数调用的位置在哪里?为什么会出现错误?
问题描述
我的代码导致错误。它说语法错误:无法分配函数调用。我在 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(...)
那我可以理解错误了。我正在将标签功能分配给某些东西。但这一次,我纠正了这一点!为什么会出现错误?
解决方案
您必须擦除)
at 宽度。
所以正确的字符串是这样的:
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 as tk 然后 tk.Label() - JacksonPro
最后你必须看看你的.place()
方法。我不确定哪个参数有什么价值,所以你必须纠正这个。