Python Forum
Curses could not find terminal
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Curses could not find terminal
#10
I think what may happen is that the lxterminal closes immediately after the program exits. You could try

import argparse
import subprocess
import sys
import traceback
 
def main_work(args):
    print('Hello from term-example')
 
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--noterminal',
        help="don't start a new terminal'",
        action='store_true')
    ns = parser.parse_args()
    try:
        sys.stdout.fileno()
    except Exception:
        # not a terminal for sure
        if ns.noterminal:
            raise RuntimeError('Need a terminal to run.')
        else:
            subprocess.call(['lxterminal', '-e', '{} {} --noterminal'.format(sys.executable, __file__)])
    else:
        try:
            main_work(ns)
        except Exception:
            if ns.noterminal:
                traceback.print_exc()
                input()# <---- this is to prevent the program to end and close the terminal
            else:
                raise
        else:
            if ns.noterminal:
                input() # <---- this is to prevent the program to end and close the terminal
     
if __name__ == '__main__':
    main()
Also you can try to run directly this command in a terminal to see if it says anything (this is not python):

lxterminal -e "python3 Calculator.py --noterminal"
Edit: I installed lxterminal in my kubuntu system and the above code works!
Edit: Support added for holding the terminal if the program fails (with exception).
Reply


Messages In This Thread
Curses could not find terminal - by Solstice - Jan-04-2018, 02:18 PM
RE: Curses could not find terminal - by Gribouillis - Jan-04-2018, 04:13 PM
RE: Curses could not find terminal - by Solstice - Jan-04-2018, 04:22 PM
RE: Curses could not find terminal - by Gribouillis - Jan-04-2018, 04:32 PM
RE: Curses could not find terminal - by Solstice - Jan-04-2018, 05:27 PM
RE: Curses could not find terminal - by Gribouillis - Jan-04-2018, 06:25 PM
RE: Curses could not find terminal - by Solstice - Jan-04-2018, 08:02 PM
RE: Curses could not find terminal - by Gribouillis - Jan-04-2018, 08:57 PM
RE: Curses could not find terminal - by Solstice - Jan-05-2018, 01:56 PM
RE: Curses could not find terminal - by Gribouillis - Jan-05-2018, 03:28 PM
RE: Curses could not find terminal - by sparkz_alot - Jan-05-2018, 04:01 PM
RE: Curses could not find terminal - by Gribouillis - Jan-05-2018, 04:23 PM
RE: Curses could not find terminal - by sparkz_alot - Jan-05-2018, 04:56 PM
RE: Curses could not find terminal - by Gribouillis - Jan-06-2018, 07:56 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I want to be able to scroll up in curses to see previous text. Caiden 1 860 Jul-28-2023, 01:15 PM
Last Post: deanhystad
  curses issue otalado 2 2,849 Jun-29-2021, 02:07 PM
Last Post: tmz
  How to make curses.border() use A_BOLD atttribute? pjfarley3 0 4,988 Feb-03-2021, 11:22 PM
Last Post: pjfarley3
  Curses script doesn't work wavic 1 4,267 Jan-08-2021, 09:11 PM
Last Post: wavic
  Why aren't all curses panel functions supported in python curses.panel? pjfarley3 2 2,755 Jul-22-2020, 11:08 PM
Last Post: pjfarley3
  curses library autompav96 2 2,972 Mar-02-2019, 02:12 AM
Last Post: woooee
  curses key codes not working jgrillout 0 3,087 Feb-11-2019, 01:46 AM
Last Post: jgrillout
  Pretty table and curses? MuntyScruntfundle 0 2,969 Oct-16-2018, 10:22 AM
Last Post: MuntyScruntfundle
  curses.initscr doesn't work zaphod424 3 9,950 Feb-28-2018, 12:36 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020