所以当我加载模块并启动函数init()时一切正常,但是当init()通过字典在同一个类(Clock())中启动另一个函数时,它返回我: AttributeError:'int'对象没有属性'lcd'
#!/usr/bin/python
import math
import time
import os
import sys
from time import gmtime, strftime, sleep, time
import Adafruit_CharLCD as LCD
# Initialize the LCD using the pins
class screen:
lcd = LCD.Adafruit_CharLCDPlate()
buttons = ( (LCD.SELECT, 0),
(LCD.LEFT, 1),
(LCD.UP, 2),
(LCD.DOWN, 3),
(LCD.RIGHT, 4) )
button = 0
is_pressed = 0
pos = (0,0) # x,y
menu_height = (0)
frame = 0
frameperiod = 0
def Clock(self):
print "Clock"
self.lcd.clear()
self.lcd.message('Zegar\n')
self.lcd.message(strftime("%H:%M:%S"))
#Force update!
menu = {
(0,0) : Clock,
}
def process(self):
print "Process"
sleep(100)
for tbutton in buttons:
if self.lcd.is_pressed(tbutton[0]):
is_pressed=1
if is_pressed==1: #len(array)
#move
if button[1] == 1 and pos[1] == 0 and pos[0]>0:
pos[0]=pos[0]-1 #left
if button[1] == 4 and pos[1] == 0 and pos[0]<len(menu_height):
pos[0]=pos[0]+1 #right
if button[1] == 2 and pos[1]>0:
pos[1]=pos[1]-1 #up
if button[1] == 3 and pos[1]<=menu_height[pos[0]]:
pos[1]=pos[1]+1
is_pressed=0
print pos
if frame==0:
self.menu[pos](pos[1])
#todo button[1]=1?
is_pressed=0
def init(self):
self.lcd.set_color(0.0, 1.0, 1.0)
self.lcd.clear()
self.lcd.message("Inicjalizacja")
print "Init"
self.menu[(0,0)](0)
return
答案 0 :(得分:0)
当您致电Clock
时,您并未在对象上调用它。您将其称为独立功能。因此,您需要提供self
作为参数。
self.menu[(0, 0)](self)
我不确定你为什么试图通过0
。 Clock
并不期望int
参数。