Hi all, I can convert my .py or .pyw files into EXE no problem. The thing is they only display a console for about a tenth of a second if they have a GUI made with tkinter. If it is a console only program then the exe works fine. Any help? I use cx_freeze. I'm also using python 3.1

Here is the code I wish to convert, if someone can get it to work then I would be grateful if the can tell me how.

from tkinter import * 

print ('Ignore the console, it is here only for bug reports.') 

root = Tk() 

root.geometry("300x150+300+300") 


pilotpln= 0 
enempln = 0 


class AppUI(Frame): 

    def __init__(self, master=None):
        Frame.__init__(self, master, relief=SUNKEN, bd=2)

        self.menubar = Menu(self) 

        menu = Menu(self.menubar, tearoff=0) 
        self.menubar.add_cascade(label="File", menu=menu) 
        menu.add_command(label="Save", command=writefile) 
        menu.add_command(label="Exit", command=root.quit)

        try:
            self.master.config(menu=self.menubar)
        except AttributeError:
            
            self.master.tk.call(master, "config", "-menu", self.menubar)


def setnumpilot(event): 
    global pilotpln
    if var.get() == 'MOSQ':
        pilotpln = 57
    elif var.get() == 'P-38J':
        pilotpln = 82
    elif var.get() == '109F-4':
        pilotpln = 13


def setnumenem(event):
    global enempln
    if var2.get() == 'MOSQ':
        enempln = 57
    elif var2.get() == 'P-38J':
        enempln = 82
    elif var2.get() == '109F-4':
        enempln = 13
        
name = pilotpln 


#str0 = filename1 I only have the strs that equal pilot/enempln here for my reading, they don't have to be.

str1 = \
"""
0x0
ndisles
(default)
0
[MISSION]
One On One P51Ds East
0
0
0:0:0:0:0.00:0.00:0.00:0.00:0.00
0,0
0,0
0
[ROUTES]
P51D Solo Route
[WAYPOINTS]
78799.12,0.00,-68238.32,78909.61,0.00,-68340.31,0
[SEGMENTS]
0,0,14.67,10.25,0.00,150.37,0.00,0.00,0.00
[ENDSEGMENTS]
78909.61,0.00,-68340.31,82594.45,0.00,-72018.68,1
[SEGMENTS]
0,1,234.67,22.19,500.00,5206.57,0.00,0.00,0.00
[ENDSEGMENTS]
82594.45,0.00,-72018.68,85624.53,0.00,-75121.86,0
[SEGMENTS]
1073741824,3,366.67,11.83,500.00,4337.18,0.00,0.00,0.00
[ENDSEGMENTS]
85624.53,0.00,-75121.86,24662.35,0.00,-134308.29,0
[SEGMENTS]
1375731712,3,366.67,231.73,14000.00,84967.18,0.00,0.00,0.00
[ENDSEGMENTS]
24662.35,0.00,-134308.29,-29689.92,0.00,-134308.29,0
[SEGMENTS]
1073741824,5,440.00,123.53,14000.00,54352.27,0.00,0.00,0.00
[ENDSEGMENTS]
-29689.92,0.00,-134308.29,-30687.21,0.00,-83446.53,0
[SEGMENTS]
1073741824,5,440.00,115.62,14000.00,50871.54,0.00,0.00,0.00
[ENDSEGMENTS]
-30687.21,0.00,-83446.53,23714.99,0.00,-83874.91,0
[SEGMENTS]
1073741824,5,440.00,123.65,14000.00,54403.88,0.00,0.00,0.00
[ENDSEGMENTS]
23714.99,0.00,-83874.91,86398.53,0.00,-57225.37,0
[SEGMENTS]
1375731716,3,293.33,232.20,1500.00,68113.32,0.00,0.00,0.00
[ENDSEGMENTS]
86398.53,0.00,-57225.37,72585.98,0.00,-71411.75,-2147483648
[SEGMENTS]
1073741824,8,293.33,67.50,1000.00,19800.00,0.00,0.00,0.00
[ENDSEGMENTS]
72585.98,0.00,-71411.75,83204.67,0.00,-81750.64,-2147483648
[SEGMENTS]
1073741824,9,293.33,50.52,750.00,14820.57,0.00,0.00,0.00
[ENDSEGMENTS]
83204.67,0.00,-81750.64,87808.86,0.00,-77021.84,-2147483648
[SEGMENTS]
1073741824,10,293.33,22.50,500.00,6600.00,0.00,0.00,0.00
[ENDSEGMENTS]
87808.86,0.00,-77021.84,80973.19,0.00,-70366.31,1
[SEGMENTS]
1073741824,11,234.67,40.66,0.00,9540.57,0.00,0.00,0.00
[ENDSEGMENTS]
[ENDWAYPOINTS]
[FLIGHTS]
East To West
196608,10,1,"""

str2 = str(pilotpln)
str21 = ','
str22 = str(pilotpln)

str3 = \
""",0.000000,0.000000,0.000000,78774.522643,0.000000,-68214.061304,0,0.000000
[WEAPONSETS]
0
0
0
1
[ENDWEAPONSETS]
[ENDFLIGHTS]
[ENDROUTES]
[GROUPNAME]
"""
#str0
str30 = \
"""
0x0
[ENDGROUPNAME]
[ENDMISSION]
[MISSION]
One On One P51Ds West
1
1
0:0:0:0:0.00:0.00:0.00:0.00:0.00
0,0
0,0
0
[ROUTES]
P51D Solo
[WAYPOINTS]
-83376.87,0.00,-30590.44,-83490.17,0.00,-30692.41,0
[SEGMENTS]
0,0,14.67,10.39,0.00,152.42,0.00,0.00,0.00
[ENDSEGMENTS]
-83490.17,0.00,-30692.41,-88135.27,0.00,-35326.18,0
[SEGMENTS]
0,1,234.67,27.96,500.00,6561.16,0.00,0.00,0.00
[ENDSEGMENTS]
-88135.27,0.00,-35326.18,-90050.32,0.00,-37547.21,0
[SEGMENTS]
1073741824,3,366.67,8.00,500.00,2932.64,0.00,0.00,0.00
[ENDSEGMENTS]
-90050.32,0.00,-37547.21,-9756.81,0.00,-134696.10,0
[SEGMENTS]
1375731712,3,366.67,343.73,14000.00,126035.53,0.00,0.00,0.00
[ENDSEGMENTS]
-9756.81,0.00,-134696.10,45883.98,0.00,-134025.73,0
[SEGMENTS]
1073741824,5,440.00,126.47,14000.00,55644.83,0.00,0.00,0.00
[ENDSEGMENTS]
45883.98,0.00,-134025.73,46554.35,0.00,-84418.27,0
[SEGMENTS]
1073741824,5,440.00,112.75,14000.00,49611.99,0.00,0.00,0.00
[ENDSEGMENTS]
46554.35,0.00,-84418.27,-13199.90,0.00,-84900.41,0
[SEGMENTS]
1073741824,5,440.00,135.81,14000.00,59756.19,0.00,0.00,0.00
[ENDSEGMENTS]
-13199.90,0.00,-84900.41,-77573.40,0.00,-20025.08,0
[SEGMENTS]
1375731713,3,293.33,311.57,1500.00,91393.42,0.00,0.00,0.00
[ENDSEGMENTS]
-77573.40,0.00,-20025.08,-91414.89,0.00,-34183.23,-2147483648
[SEGMENTS]
1073741824,8,293.33,67.50,1000.00,19800.00,0.00,0.00,0.00
[ENDSEGMENTS]
-91414.89,0.00,-34183.23,-80817.32,0.00,-44543.77,-2147483648
[SEGMENTS]
1073741824,9,293.33,50.52,750.00,14820.57,0.00,0.00,0.00
[ENDSEGMENTS]
-80817.32,0.00,-44543.77,-76203.49,0.00,-39824.39,-2147483648
[SEGMENTS]
1073741824,10,293.33,22.50,500.00,6600.00,0.00,0.00,0.00
[ENDSEGMENTS]
-76203.49,0.00,-39824.39,-83025.55,0.00,-33154.91,1
[SEGMENTS]
1073741824,11,234.67,40.66,0.00,9540.57,0.00,0.00,0.00
[ENDSEGMENTS]
-83025.55,0.00,-33154.91,-85497.40,0.00,-30685.70,0
[SEGMENTS]
1073741824,12,88.00,0.00,0.00,0.00,0.00,0.00,0.00
[ENDSEGMENTS]
-85497.40,0.00,-30685.70,-85634.34,0.00,-30540.21,0
[SEGMENTS]
1073741824,0,14.67,13.62,0.00,199.81,0.00,0.00,0.00
[ENDSEGMENTS]
-85634.34,0.00,-30540.21,-85274.87,0.00,-30197.86,1
[SEGMENTS]
1073741824,0,14.67,33.85,0.00,496.40,0.00,0.00,0.00
[ENDSEGMENTS]
[ENDWAYPOINTS]
[FLIGHTS]
West To East
196608,10,1,10"""

str33 = str(enempln) + ','
str34 = ','
str4 = str(enempln)

str5 = \
""",0.000000,0.000000,0.000000,-83370.343819,0.000000,-30572.162808,0,0.000000
[WEAPONSETS]
0
0
0
1
[ENDWEAPONSETS]
[ENDFLIGHTS]
[ENDROUTES]
[GROUPNAME]
"""
#str6 = filename1

str7 = \
"""
0x0
[ENDGROUPNAME]
[ENDMISSION]
"""



def writefile():
    x = var.get() #x is the name of the plane the user selects for himself
    space = " "
    y = 'vs'
    space2 = " "
    z = var2.get() #name of plane for the enemy
    zz = '.mis' #has to be a .mis file
    filename = x + space+ y + space2 + z + zz  #put it all together and whaddya get?  X vs Y.mis!
    filename1 = x + space+ y + space2 + z
    str6 = filename1
    str0 = filename1
    str2 = str(pilotpln) #had to define within function.  I used them above with the other strings for readability
    str4 = str(enempln) 
    str21 = ','
    str22 = str(pilotpln)
    str33 = str(enempln)
    str34 = ','
    
    done = 1 
    namelist = [str0,str1,str2,str21,str22,str3,str0,str30,str33,str34,str4,str5,str0,str7]
    while done: 
        if type(name) == type(""):
            namelist.append(name)
            done = 0
        else:
            done = 0

        FILE = open(filename,"w") 
        FILE.writelines(namelist) 

        FILE.close() 


app = AppUI(root) 
app.pack() 

var = StringVar()
var.set("Choose a plane for yourself.") 

var2 = StringVar()
var2.set("Choose a plane for the enemy.")

OptionMenu(root, var, 'P-51D',"P-38J","109F-4", command=setnumpilot).pack() 
OptionMenu(root, var2, 'P-51D',"P-38J","109F-4", command=setnumenem).pack()

b = Button(root, text="Save mission file", fg="blue", command=writefile)
b.pack()

quit = Button(root, text="QUIT", fg="red", command=root.quit)
quit.pack()


root.mainloop()

Thank you.

Recommended Answers

All 6 Replies

does cx_freeze support Python3.x?
I always use py2exe and doesn't support 3.x yet

I think that is it, I will convert my code to 2.6 when I get home.

Just visited their site and they provide installers for All versions of Python.
You may need to check that :)

Just visited their site and they provide installers for All versions of Python.
You may need to check that :)

I am using the python 3.1 cxfreeze, still no joy :(.

I you can the best way is downgrade your code to 2.5 and use gui2exe
Not so fun though

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.