私は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
が必要になります
として、クラスの外で利用できるようにwiil。より有用な情報がある。問題を引き起こす線。 – furas