So I am kinda stuck on this one and I am really not sure where to go from here. I am trying to create a tkinter gui to control a Parallax RFID read/write module. So far I have managed to code the tkinter window, and created a button, when pressed it will begin to read a rfid tag. My problem is I do not know how to create a label that will update, so that the tag's memory contents is shown in the tkinter window and not just the console.
This is python 2.7 code.
Here is the code I am using to print the tags contents to console.
print ("Read App Starting...")
print ("Reading tag's User Data...")
for ix in range(3, 31):
while True:
ser.write('!RW' + chr(CMD_READ) + chr(ix)) # send command
buf = ser.read(5) # get bytes (will block until received)
if buf[0] == chr(ERR_OK): # if valid data received with no error, continue
break
print ("%2d") % ix, ": ",
for iy in range(1,len(buf)): # display data
sys.stdout.write("%02X" % ord(buf[iy]))
print("")
I have saved this to a file and am importing it into my tkinter code.
Tkinter app
from tkinter import *
import read_tag
class Window(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
self.init_window()
#Creation of init_window
def init_window(self):
# changing the title of our master widget
self.master.title("GUI")
# allowing the widget to take the full space of the root window
self.pack(fill=BOTH, expand=1)
# creating a button instance
readbutton = Button(self, text="Read Tag", command=read_tag.main)
# placing the button on my window
readbutton.place(x=0, y=0)
outputlabel = Label(self, text="Tag Data :")
outputlabel.place(x=60, y=0)
output = Label(self, command=?)
output.place(x=70, y=0)
root = Tk()
#size of the window
root.geometry("400x300")
app = Window(root)
root.mainloop()