Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 786787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:05:56+00:00 2026-05-14T21:05:56+00:00

I have a python console app. Like most python console apps it uses the

  • 0

I have a python console app. Like most python console apps it uses the OptionParser module to take arguments. I’ve now developed a GUI for my app using wxPython and i’d like to integrate the two. I’d like my app to be run both from the console and from the OS’s UI. When it is invoked from the console it runs as a console app and when it is double clicked in the OS’s UI, it runs as a GUI app. How could I do something like this? Could someone show me a a snippet of what the __main__ block should be like?

Thanks a ton.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:05:57+00:00Added an answer on May 14, 2026 at 9:05 pm

    can you pass args to the app then use the arg parser?

    if __name__ == "__main__":
      from  optparse import OptionParser
    
      parser = OptionParser() 
      parser.add_option("-g","--gui_mode",
                        dest="guimode",
                        help="start program in gui mode",
                       action="store_true")
    
      (options,args) = parser.parse_args()
    
      if (options.guimode):
          print "start wx app"
      else:
          print "start cmd line app"
    

    Edit:
    Sorry, misread, i thought you wanted to start from another Wx App. rather than from the “OS UI”
    I don’t know of a great, cross platform way to do this. The issue is that in windows .py files are usually associated with the python.exe .pyw files are similar, but don’t have a console window.
    So you would actually have to modify the OS to support this behaviour. For example you could create a shortcut (in windows/gnome/kde) that launches the program with –gui_mode or use a mechanism like @Austin suggested in an *nix OS.
    Some of this stuff can be automated by disttools if you are installing an application

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a console daemon that is run by a GUI application. When the
I have a file, light.py that I'm trying to debug. In the python console,
I'm going about deleting entries from my python app engine server like this: try:
I want my app to loop in python but have a way to quit.
Possible Duplicate: How to hide console window in python? I have a simple script
I have a c console app which converts a c file to a html
I have a C# console app that serializes a POCO class to a JSON
I'm trying to make a simple hello-world executable python gui app in windows using
I have multiple python processes running in their console output windows. I can set
Original Question App Engine SDK 1.6.5 Python 2.7 webapp2 I have implemented webapp2 schemes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.