Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 如何将python聊天程序编译为exe?_Python 2.7_Chat - Fatal编程技术网

Python 2.7 如何将python聊天程序编译为exe?

Python 2.7 如何将python聊天程序编译为exe?,python-2.7,chat,Python 2.7,Chat,这是双向聊天室“主人”的代码。客户机的代码非常相似。我试着用各种方法将它们编译成一个exe,但没有一个有好的结果。exe根本不运行。我得到了所有的模块,我尝试了许多代码(许多代码也将dll文件等添加到程序中)。我尝试将其编译为pyw,因为它里面有图形。另外还有一个py文件,其中包含这两个(客户端和主机)pyw文件以某种方式获得的更多信息,但它们仍然可以在没有python.exe的情况下运行。我不知道如何才能帮助你理解,所以如果你有任何问题,请告诉我。提前谢谢 这是python 2.7代码中的主机

这是双向聊天室“主人”的代码。客户机的代码非常相似。我试着用各种方法将它们编译成一个exe,但没有一个有好的结果。exe根本不运行。我得到了所有的模块,我尝试了许多代码(许多代码也将dll文件等添加到程序中)。我尝试将其编译为pyw,因为它里面有图形。另外还有一个py文件,其中包含这两个(客户端和主机)pyw文件以某种方式获得的更多信息,但它们仍然可以在没有python.exe的情况下运行。我不知道如何才能帮助你理解,所以如果你有任何问题,请告诉我。提前谢谢

这是python 2.7代码中的主机:

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,())
导入线程
从ChatFns进口*
#---------------------------------------------------#
#---------初始化连接变量-----------#
#---------------------------------------------------#
#启动套接字并将端口绑定到主机PC
WindowTitle='聊天-主机用户'
s=套接字(AF_INET,SOCK_STREAM)
HOST=gethostname()
端口=8000
康涅狄格州
s、 绑定((主机、端口))
#---------------------------------------------------#
#------------------鼠标事件-------------------#
#---------------------------------------------------#
def ClickAction():
#将消息写入聊天窗口
EntryText=FilteredMessage(EntryBox.get(“0.0”,结束))
LoadMyEntry(聊天日志、EntryText)
#滚动至聊天窗口的底部
ChatLog.yview(完)
#输入框中的Erace上一条消息
EntryBox.delete(“0.0”,结束)
#把我的梅萨吉送给所有其他人
conn.sendall(入口文本)
#---------------------------------------------------#
#-----------------键盘事件-----------------#
#---------------------------------------------------#
def压力动作(事件):
EntryBox.config(状态=正常)
单击操作()
def禁用条目(事件):
EntryBox.config(状态=已禁用)
#---------------------------------------------------#
#-----------------图形管理---------------#
#---------------------------------------------------#
#创建一个窗口
base=Tk()
基本标题(WindowTitle)
基础几何(“400x470”)
可调整大小(宽度=假,高度=假)
#创建聊天窗口
聊天记录=文本(基本,bd=0,bg=“白色”,height=“8”,width=“50”,font=“Arial”,)
插入(结束,“正在等待客户端用户连接…\n”)
ChatLog.config(状态=已禁用)
#将滚动条绑定到聊天窗口
scrollbar=scrollbar(base,command=ChatLog.yview,cursor=“heart”)
ChatLog['yscrollcommand']=scrollbar.set
#创建发送消息的按钮
SendButton=按钮(底部,font=30,text=“Send”,width=“12”,height=5,
bd=0,bg=“#e6e6”,activebackground=“#FA5858”,
命令=单击操作)
#创建用于输入消息的框
EntryBox=Text(基本,bd=0,bg=“白色”,width=“29”,height=“5”,font=“Arial”)
EntryBox.bind(“,DisableEntry)
EntryBox.bind(“,按Action)
#将所有组件放置在屏幕上
滚动条位置(x=376,y=6,高度=386)
聊天记录位置(x=6,y=6,高度=386,宽度=370)
入口盒位置(x=128,y=401,高度=60,宽度=265)
SendButton.place(x=6,y=401,高度=60)
#---------------------------------------------------#
#----------------连接管理--------------#
#---------------------------------------------------#
def GetConnected():
s、 听(1)
全球康涅狄格州
conn,addr=s.accept()
LoadConnectionInfo(聊天记录,'连接到:'+str(addr)+'\n----------------------------------------------------------------------)
而1:
尝试:
数据=conn.recv(1024)
LoadOtherEntry(聊天日志、数据)
如果base.focus_get()=无:
FlashMyWindow(WindowTitle)
播放声音('notif.wav')
除:
LoadConnectionInfo(聊天记录,'\n[用户已断开连接]\n[等待他们连接…]\n')
GetConnected()
康涅狄格州关闭
线程。启动新线程(GetConnected,())

base.mainloop()

Python是一种解释语言,不应该编译成.exe文件。但是,有一些工具,如,可以用Python创建一个可执行文件,将解释器本身绑定到文件中。

“我尝试过用各种方法将它们编译成一个可执行文件,但没有一个得到很好的结果。”您尝试了什么?你能把这个问题的答案编辑成你的问题吗?