not7CD
not7CD

Reputation: 574

Don't focus Python subprocess, linux

I'm running a script in a console to help me in a repetitive task.
I want open image in gallery and write down numbers from an image.

feh = subprocess.Popen(['feh', 'tmp.jpg'])

print ("Input number from image:")
number = input()

feh.kill()

This code works, but window managers keep focusing feh, which adds an additional step of refocusing console window. Is there an additional argument I can pass to prevent this behavior or another way around?

Upvotes: 3

Views: 1252

Answers (2)

Thiner
Thiner

Reputation: 345

Python has native GUI modules, named tkinter.

GUI program can be terrifyingly easy to write, if it is python.

#!/usr/bin/python2 -i
from Tkinter import *
from PIL import *
import os

files = [f for f in os.listdir('.') if f.endswith(".png")]

root = Tk()
label = Label(root)
label.pack()

for name in files:
    im = PhotoImage(file=name)
    label.config(image=im)
    print("your number plz")
    input_str = raw_input()

Upvotes: 3

not7CD
not7CD

Reputation: 574

One dirty workaround is to simply refocus window by mouse.

I used xdotool

feh = subprocess.Popen(['feh', 'tmp.jpg'])

time.sleep(0.1)
subprocess.call(['xdotool', 'click', '1'])

something = input()

feh.kill()

Upvotes: 3

Related Questions