我目前是一名新手蟒蛇学生。为了好玩,我决定尝试模拟一个led持久性视觉程序,然而,在我编码的早期,我已经碰到了一堵砖墙。我的led类构造函数一直在初始化,我不知道为什么。下面的代码对我想要做的事情有点不言自明。我正在尝试生成一条LED并将它们全部设置为开启模式。但是,如果您运行以下代码,您将看到只有最终的led被打开。
import Tkinter as tk
root=tk.Tk()
ledboard=tk.Frame(root, height=50, width=1000)
ledboard.pack()
class led(object):
def __init__(self):
self._mode=0
self._led=tk.Label(ledboard,text="led", padx=20, bg="blue")
self._led.pack()
def setmode(self,x):
self._mode=x
if self._mode==1:
self._led.config(bg="red")
else:
self._led.config(bg="grey")
def getmode(self):
print self._mode
class ledstrip(object):
def __init__(self):
self._strip=["led1","led2","led3","led4","led5","led6","led7"]
for i in self._strip:
self._i=led()
def getstripmode(self):
stripmode=[]
self._strip=["led1","led2","led3","led4","led5","led6","led7"]
for i in self._strip:
stripmode.append(self._i.getmode())
def setstripmode(self, partial):
self._strip=["led1","led2","led3","led4","led5","led6","led7"]
for i in self._strip:
self._i.setmode(1)
x=ledstrip()
x.setstripmode([1,1,1,1,1,1,0])
root.mainloop()