我正在编写我的第一个 Python 脚本并得到错误NameError: global name 'board' is not defined
。为什么python会抛出这个错误,如何解决?
class Screen(QtGui.QMainWindow):
def __init__(self):
super(Screen, self).__init__()
self.initUI()
def toggleLED(self, pressed):
source = self.sender()
if self.LedOn:
source.setText('LED Off')
self.LedOn = 0
board.setHigh(13)
else:
source.setText('LED On')
self.LedOn = 1
board.setLow(13)
def main():
app = QtGui.QApplication(sys.argv)
screen = Screen()
board = Arduino('COM3')
sys.exit(app.exec_())
if __name__ == '__main__':
main()