0

I'm building a windows forms application using pythonnet. I've built a pretty basic app, code below!, I used pyinstaller to turn it into an exe. But every time I run the exe file, a console window opens alongside the gui app. I can't find a way to turn that console window off. Any help will be highly appreciated!

p.s. I hope my question makes sense!

here's the code:

import clr

clr.AddReference('System.IO')
clr.AddReference('System.Drawing')
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Threading')

import System
import System.IO
import System.Drawing
import System.Windows.Forms
import System.Threading

class homePage(System.Windows.Forms.Form):

    def __init__(self):
        
        self.Text = "AppTest1"
        self.BackColor = System.Drawing.Color.FromArgb(200, 150, 190)
        self.ClientSize = System.Drawing.Size(600, 600)
    
    def run(self):    
        System.Windows.Forms.Application.Run(self)

def main_form_thread():
    app_form = homePage()
    app_form.run()

if __name__ == "__main__":
    main_form_thread()

The answers I get on the web are about how I can run an external exe file from my new code by creating a new process object and setting its UseShellExecute to false. But I don't want to call my exe file from another exe file, I want to be able to run the main exe file and not have the console window open. Also, I can't get the System.Diagnostics.Process to work in pythonnet.

p.s. I'm just starting pythonnet.

abaid
  • 31
  • 6

1 Answers1

0

OKAY! I GOT IT!! And comes out my question was wrong! I should've asked, how should I disable the console window when building with PyInstaller. And that question has already been answered here

If you're too lazy to click links, then just simply add this flag --noconsole when building with pyinstaller, like that pyinstaller --noconsole your_script_name.py

abaid
  • 31
  • 6