2016-09-19 3 views
-1

Nun, das ist ein Code für den "Host" eines Zwei-Wege-Chatrooms. Der Code des Clients ist sehr ähnlich. Ich habe versucht, beide in eine exe mit verschiedenen Möglichkeiten zu kompilieren und keiner von ihnen hatte ein schönes Ergebnis. Die exe läuft einfach nicht. Ich habe alle Module, ich habe viele Codes ausprobiert (viele hinzufügen die DLL-Dateien usw. in das Programm auch.) Ich versuche, es als Pyw zu kompilieren, da es Grafiken im Inneren hat. Es gibt noch eine Py-Datei, die weitere Informationen enthält, die diese beiden (client und host) Pyw-Dateien irgendwie bekommen, aber sie können trotzdem ohne sie mit python.exe laufen. Ich weiß nicht, wie ich dir helfen kann zu verstehen, lass es mich wissen, wenn du irgendwelche Fragen hast. Danke im Voraus.Wie kompiliere ich ein Python-Chat-Programm mit einer exe?

Dies ist der Host in Python 2.7 Code:

import thread 
from ChatFns import * 



#---------------------------------------------------# 
#---------INITIALIZE CONNECTION VARIABLES-----------# 
#---------------------------------------------------# 
#Initiate socket and bind port to host PC 
WindowTitle = 'Chat - Host User' 
s = socket(AF_INET, SOCK_STREAM) 
HOST = gethostname() 
PORT = 8000 
conn = '' 
s.bind((HOST, PORT)) 



#---------------------------------------------------# 
#------------------ MOUSE EVENTS -------------------# 
#---------------------------------------------------# 
def ClickAction(): 
    #Write message to chat window 
    EntryText = FilteredMessage(EntryBox.get("0.0",END)) 
    LoadMyEntry(ChatLog, EntryText) 

    #Scroll to the bottom of chat windows 
    ChatLog.yview(END) 

    #Erace previous message in Entry Box 
    EntryBox.delete("0.0",END) 

    #Send my mesage to all others 
    conn.sendall(EntryText) 





#---------------------------------------------------# 
#----------------- KEYBOARD EVENTS -----------------# 
#---------------------------------------------------# 
def PressAction(event): 
    EntryBox.config(state=NORMAL) 
    ClickAction() 
def DisableEntry(event): 
    EntryBox.config(state=DISABLED) 




#---------------------------------------------------# 
#-----------------GRAPHICS MANAGEMENT---------------# 
#---------------------------------------------------# 

#Create a window 
base = Tk() 
base.title(WindowTitle) 
base.geometry("400x470") 
base.resizable(width=FALSE, height=FALSE) 

#Create a Chat window 
ChatLog = Text(base, bd=0, bg="white", height="8", width="50", font="Arial",) 
ChatLog.insert(END, "Waiting for client user to connect...\n") 
ChatLog.config(state=DISABLED) 

#Bind a scrollbar to the Chat window 
scrollbar = Scrollbar(base, command=ChatLog.yview, cursor="heart") 
ChatLog['yscrollcommand'] = scrollbar.set 

#Create the Button to send message 
SendButton = Button(base, font=30, text="Send", width="12", height=5, 
        bd=0, bg="#E6E6E6", activebackground="#FA5858", 
        command=ClickAction) 

#Create the box to enter message 
EntryBox = Text(base, bd=0, bg="white",width="29", height="5", font="Arial") 
EntryBox.bind("<Return>", DisableEntry) 
EntryBox.bind("<KeyRelease-Return>", PressAction) 

#Place all components on the screen 
scrollbar.place(x=376,y=6, height=386) 
ChatLog.place(x=6,y=6, height=386, width=370) 
EntryBox.place(x=128, y=401, height=60, width=265) 
SendButton.place(x=6, y=401, height=60) 



#---------------------------------------------------# 
#----------------CONNECTION MANAGEMENT--------------# 
#---------------------------------------------------# 
def GetConnected(): 
    s.listen(1) 
    global conn 
    conn, addr = s.accept() 
    LoadConnectionInfo(ChatLog, 'Connected with: ' + str(addr) + '\n---------------------------------------------------------------') 

    while 1: 
     try: 
      data = conn.recv(1024) 
      LoadOtherEntry(ChatLog, data) 
      if base.focus_get() == None: 
       FlashMyWindow(WindowTitle) 
       playsound('notif.wav') 
     except: 
      LoadConnectionInfo(ChatLog, '\n [ User disconnected. ]\n [ Waiting for them to connect...] \n ') 
      GetConnected() 

    conn.close() 

thread.start_new_thread(GetConnected,()) 

base.mainloop()

+0

"Ich habe versucht, beide in eine exe mit verschiedenen Möglichkeiten zu kompilieren und keiner von ihnen hatte ein schönes Ergebnis." Was hast du versucht? Würden Sie die Antwort darauf in Ihre Frage ändern? –

Antwort

0

Python ist eine interpretierte Sprache, es ist eigentlich nicht in eine EXE-Datei kompiliert werden. Es gibt jedoch Tools wie http://py2exe.org/, die mit Python eine ausführbare Datei erstellen, die den Interpreter selbst in die Datei einbindet.

+0

Es funktioniert jedoch nicht für diesen Code. –

Verwandte Themen