-
-
Save biggidvs/60a47f02d3ab956c1ae27200545ad753 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tkinter as tk | |
from xml.dom import minidom | |
import threading | |
from time import sleep | |
dist = 0.0 | |
class parse_xml(threading.Thread): | |
global dist | |
def run(self): | |
while(True): | |
try: | |
xmldoc = minidom.parse('data.xml') | |
itemlist = xmldoc.getElementsByTagName('object1') | |
for items in itemlist: | |
x = items.getElementsByTagName('x1')[0].childNodes[0].data | |
x_per_inch = (.7129988670349121-.28)/28 | |
xml_distance = float(x) | |
if float(xml_distance) <= .28: | |
dist = 0.0 | |
print("STOP") | |
else: | |
dist = ((xml_distance-.28)//x_per_inch) | |
# if we get caught in a write loop, keep old data | |
except Exception as e: | |
return | |
class Gui(object): | |
global dist | |
def __init__(self): | |
self.root = tk.Tk() | |
self.lbl = tk.Label(self.root, text="") | |
#self.lbl = Lab | |
self.updateGUI() | |
def run(self): | |
self.lbl.pack() | |
self.lbl.after(1000, self.updateGUI) | |
self.root.mainloop() | |
def updateGUI(self): | |
msg = str(dist) | |
self.lbl["text"] = msg | |
self.root.update() | |
self.lbl.after(1000, self.updateGUI) | |
if __name__ == "__main__": | |
parse_xml().start() | |
Gui().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment