0

I'm using libdmtx to read 2D codes from png files with this code:

#!/usr/bin/python
import os
import Tkinter
from Tkinter import *
from tkFileDialog import askopenfilename

top = Tkinter.Tk()
top.geometry("200x200")
content = StringVar()
label = Message( top, textvariable=content, width='180' )
content.set ("Choose file to read 2D code")
label.pack()

def selector():
   filename = askopenfilename() 
   cmd = "dmtxread -n %s" % (filename)
   res = Text(top)
   res.insert (INSERT, os.system(cmd))
   res.pack()

B = Tkinter.Button(top, text ="Choode file", command = selector)
B.pack()

top.mainloop()

Everything work fine, but in GUI I can't get a full output. There's just 0, but in console I get what is in 2D code. What should I do to get full output in GUI?

1 Answer 1

2

That's because os.system doesn't return the stdout of the command you executed, it just returns its exit status, which is in this case 0.

You should use the subprocess module, like this:

import subprocess

def selector():
    filename = askopenfilename() 
    p = subprocess.Popen(["dmtxread", "-n", filename], stdout=subprocess.PIPE)
    stdout, stderr = p.communicate()
    res.insert(INSERT, stdout)
    res.pack()
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.