Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Tkinter, tkFileDialog, tkSimpleDialog, time, serial, turtle
- from ScrolledText import ScrolledText
- from tkFileDialog import askopenfilename
- from tkSimpleDialog import*
- from Tkinter import*
- root = Tk()
- myFrame = Frame(root) #Frame(root, width = 800, height = 500)
- myFrame.master.title("G-code Viewer")
- myFrame.pack()
- def openfile():
- filename = askopenfilename(filetypes=[("all files", "*")])
- myFile = open(filename)
- teks=ScrolledText(root)
- Filereadlines = myFile.readlines()
- turtle.title("Visual G-code Viewer")
- for x in range(0,len(Filereadlines)):
- data = Filereadlines[x]
- splitspc = data.split(' ')
- lensplit = len(splitspc)
- if lensplit > 3:
- splitX = splitspc[1].split('X')
- splitY = splitspc[2].split('Y')
- if splitspc[0] == 'M03':
- turtle.down()
- elif splitspc[0] == 'M04':
- turtle.up()
- elif splitspc[0] == 'M18':
- turtle.up()
- print "Done"
- if splitspc[0] == 'G1':
- try:
- print "grab"
- print float(splitX[1])
- print float(splitY[1])
- turtle.goto(float(splitX[1]), float(splitY[1]))
- except IndexError as e:
- print "print gagal karena", e
- else:
- print "????"
- time.sleep(0.1)
- myFile.close()
- teks.pack(expand = YES, fill = X)#(side=LEFT, expand = YES, fill = Y)
- Button(root, text="Quit", command=root.destroy).pack(side = BOTTOM, expand = YES, fill = X)
- Button(root, text='Browse file', command=openfile).pack(side = BOTTOM, expand = YES, fill = X)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment