2016-10-20 7 views
1

私はpython3を使ってrpiのtkinterに苦労しています。私のコードに従うと、以下のエラーが表示されます。私はpython2で同じコードをrootとして使っていますが、私のledは完全に動作します。私はGPIOを使用せずにコマンドを呼び出すことができる自己を使用していますが。誰か助けてくれますか?私は感謝されます。ボタンは名前が付けられていません(python3のtkinter)

#!/usr/bin/python 

import time 
import RPi.GPIO as GPIO 
from tkinter import * 
import tkinter as tkenter code here 

GPIO.setmode(GPIO.BCM) 
GPIO.setwarnings(False) 

GPIO.setup(5, GPIO.OUT) #Luminária A 
GPIO.setup(6, GPIO.OUT) #Luminária B 
GPIO.setup(13, GPIO.IN) #Luz ambiente no setor 
GPIO.setup(19, GPIO.IN) #Pessoas no setor 

GPIO.output(5, GPIO.LOW) 
GPIO.output(6, GPIO.LOW) 

LARGE_FONT = ("Verdana", 12) 


def leD(): 

    if ((GPIO.input(5)) and (GPIO.input(6))): 
     GPIO.output(5, GPIO.LOW) 
     GPIO.output(6, GPIO.LOW) 
     showAcionamento["text"]="Lights on" 

    else: 
     GPIO.output(5, GPIO.HIGH) 
     GPIO.output(6, GPIO.HIGH) 
     showAcionamento["text"]="Lights off" 

def sairr(): 
    GPIO.cleanup() 
    exit() 


class showAcionam(tk.Tk): 


    def __init__(self, *args, **kwargs): 

     tk.Tk.__init__(self, *args, **kwargs) 
     container = tk.Frame(self) 

     container.pack(side="top", fill="both", expand = True) 

     container.grid_rowconfigure(0, weight=1) 
     container.grid_columnconfigure(0, weight=1) 

     self.frames = {} 

     frame = Acionamento(container, self) 

     self.frames[Acionamento] = frame 

     frame.grid(row=0, column=0, sticky="nsew") 

     self.show_frame(Acionamento) 


    def show_frame(self, cont): 

     frame = self.frames[cont] 
     frame.tkraise() 


class Acionamento(tk.Frame): 

    def __init__(self, parent, controller): 
     tk.Frame.__init__(self, parent) 
     label = tk.Label(self, text="Acionamento", font=LARGE_FONT) 
     label.pack(pady=10,padx=10) 


    showAcionamento = tk.Button(self, text="0% de Iuminação", command = leD) 
    showAcionamento.pack() 

    sair = tk.Button(self, text="Sair", command = sairr) 
    sair.pack() 


app = showAcionam() 
app.mainloop() 


#Error Message 
Exception in Tkinter callback 
Traceback (most recent call last): 
File "/usr/lib/python3.4/tkinter/__init__.py", line 1536, in __call__ 
return self.func(*args) 
File "/home/pi/TCC.py", line 34, in leD 
showAcionamento["text"]="Lights off" 
NameError: name 'showAcionamento' is not defined 
+1

が必要になります

app.frames[Acionamento].showAcionamento 

として、クラスの外で利用できるようにwiil。より有用な情報がある。問題を引き起こす線。 – furas

答えて

1

showAcionamento__init__にのみ存在するローカル変数です。
まず、オブジェクト変数を作成するために、クラスにself.showAcionamentoを使用する必要があります。

そして今、それはあなたがなかれ(問題の)完全なエラーメッセージを追加

app.frames[Acionamento].showAcionamento["text"] = "Lights on" 

app.frames[Acionamento].showAcionamento["text"] = "Lights off" 
+0

驚くばかりのFuras、それは今働いている!私はそれを逃していた。乾杯、 – armf1993

+0

こんにちは、私はサブフレームに苦労しています、どうすればいいですか? – armf1993

関連する問題