我正在使用tkinter创建一个GUI,该GUI显示RC522 rfid卡中的信息。在这里,我希望每0.5秒,rfid通过将以前的数据加100来写入新数据。 rc522脚本基于https://github.com/simonmonk/clever_card_kit(read.py,write.py,SimpleMFRC522.py)
Class rcinfo(tk.Frame):
def __init__(self, parent, master)
self.master = master
GPIO.setwarnings(False)
continue_reading = True
reader = SimpleMFRC522.SimpleMFRC522()
while continue_reading:
text = reader.read()
info = tk.StringVar
label = tk.Label(master, text = ' ', bg="white", textvariable=info, font=("Calibri",16,bold))
label.place(x=100, y=100, width=600, height=85)
info.set(text)
me = int(text) + 100 ///// convert previous value to integer and add 100
text = str(me) ///// convert 'me' to string
text = reader.write(text) ///// new data is written
time.sleep(0.5)
continue_reading = True
GPIO.cleanup()
但是,运行此脚本时,错误提示
“ strong> init 中的文件“ /home/pi/Readme/Readme.py”,第137行 我= int(文字)+ 100 TypeError:int()参数必须是字符串或数字,而不是'tuple'
请帮助。我不知道我哪里错了。
答案 0 :(得分:1)
错误告诉您,...
<profiles>
<profile>
<id>docker</id>
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>log4j2*.xml</exclude>
<exclude>docker/*</exclude>
</excludes>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
...
变量不允许转换为int,因为它不是text
或其他数字类型-它是一个元组。
要查看元组包含的内容,可以在分配后str
并查看得到的输出。我的猜测是,您需要直接访问元组的元素以获取所需的数据:
print(text)
变成me = int(text) + 100
。