【发布时间】:2021-12-09 07:37:38
【问题描述】:
def lbl():
lbl1=Label(self,text='hello',fg='red').place(x=10,y=10)
class login(Frame):
global self
def __init__(self,parent,controller):
Frame.__init__(self,parent)
btn=Button(self,text='view',command=lbl).place(x=40,y=40)
现在在上面的函数中,它给出了 name self is not defined 的错误
【问题讨论】:
-
你为什么把
global self放到你的班级里?也请发minimal reproducible example -
self永远不应该成为全球性的。
标签: python python-3.x class oop tkinter