mmkw43
Posts: 659
Joined: Tue Dec 24, 2013 6:18 pm

Open Lxterminal window in script?

Mon Nov 16, 2020 7:14 pm

Friends --
Probably asking the impossible (I'm good at that) but is there any way to open the Lxterminal window in a script? I need to have it open to display raspi-config.

Have tried all sorts of things with subprocess.call -- even tried root.bind for the ctl-alt-t keys etc etc. Perhaps I'm asking the impossible? many thanks.

GlowInTheDark
Posts: 1244
Joined: Sat Nov 09, 2019 12:14 pm

Re: Open Lxterminal window in script?

Mon Nov 16, 2020 7:27 pm

The obvious answer is "Yes". Just run it (using whatever syntax "Python" uses to run external programs).

If you need it to run a script (you mention raspbi-config), then you'd do:

Code: Select all

lxterminal -e raspi-config
So, the obvious question then becomes: What have you tried? In what ways has it not met your expectations?

The next question is: Why can't you just run it directly inline with your Python program? Why does it have to run in a separate terminal?

Finally, I'm sorta guessing that what's really going on here is that you want the Python program to wait for the lxterminal to finish - and that's a problem. lxterminal, unlike most other X terminals applications, has a client/server architecture, where when you run lxterminal, it doesn't actually run as a normal process, but rather just sends a message to the master lxterminal to open up another window. This makes it impossible to know when that terminal window gets closed.

To get around this problem, I would suggest installing and using either xterm or rxvt, since they behave more "normally". I generally use rxvt for most such tasks.
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

Loves Linux; loves to dance.

klricks
Posts: 7442
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Open Lxterminal window in script?

Mon Nov 16, 2020 7:35 pm

This is what I use (Python 3):

Code: Select all

subprocess.run(["lxterminal","-e","sudo", "raspi-config"])
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

mmkw43
Posts: 659
Joined: Tue Dec 24, 2013 6:18 pm

Re: Open Lxterminal window in script?

Mon Nov 16, 2020 8:59 pm

Thanks, this works fine --

subprocess.run(["lxterminal","-e","sudo", "raspi-config"])

had to use "call" instead. and now like you say, how do I get rid of the window.
which from what I just read, is pretty much impossible.

anyway, thanks.
amateur question, what does the '-e' do?

mmkw43
Posts: 659
Joined: Tue Dec 24, 2013 6:18 pm

Re: Open Lxterminal window in script?

Mon Nov 16, 2020 9:08 pm

SWEET !

Actually when you go through the process in raspi-config for localization and click finish, it closes the window.

! -- thanks much.


actually, my mistake was not creating a list in subprocess -- my bad -- I've always just done one command. from now on, step 1 is to go back and READ the python documentation.

Return to “Python”