[英]Getting a fatal error while converting my python gui program to .exe using pyinstaller
I tried to convert my Tkinter gui program to .exe file using pyinstaller autowhatsapp.py --noconsole --onefile command .But when i am launching my .exe file,i am getting a fatal error.
Can anyone help.任何人都可以帮忙。
I am using Tkinter, threading,webbrowser, socket and pywhatkit library.我正在使用 Tkinter、threading、webbrowser、socket 和 pywhatkit 库。 I am also using an icon file and a text file all stored in my python file directory.
我还使用了一个图标文件和一个文本文件,它们都存储在我的 python 文件目录中。
I am one facing this problem in those programs where I imported additional modules and used files.Otherwise I successfully converted one of my gui program without getting any fatal error我在那些导入附加模块和使用文件的程序中遇到了这个问题。否则我成功转换了我的一个 gui 程序而没有出现任何致命错误
from tkinter import *
from threading import *
import socket
import webbrowser
def is_connected():
try:
socket.create_connection(("1.1.1.1", 53))
return True
except OSError:
pass
return False
def callback(url):
webbrowser.open_new_tab(url)
def con_check():
check = Tk()
check.title("!ERROR")
check.minsize(350,150)
check.maxsize(350,150)
conn_lbl = Label(check,text="Internet connection required\nCheck your settings",font=("Comic San MS",15,"bold")).pack(pady=50)
check.mainloop()
def main():
root = Tk()
root.title("Whatsapp Message Sender")
root.minsize(500,500)
root.maxsize(500,500)
root.config(bg="#33FF99")
root.iconbitmap("whatsapp.ico")
info_text = """NOTES(Version 1.0.1)\n\n\n
\n 1> Login into https://web.whatsapp.com/ from your default web browser,ignore if already done.
\n 2> You can close the browser after logging in
\n 3> Images, videos and docs sending feature will be coming in next update
\n 4> If message is not sent, then check the recipient number and try again.
\n 5> After scheduling msg,you can minimize the app.
\n 6> WARNING! Don't close the app after scheduling msg,we will notify
\n you weather your msg is sent or not
"""
def user_info():
top = Toplevel()
top.title("How to use?")
text = Label(top,font=("Comic San MS",10,"bold"),text=info_text)
text.bind("<Button-1>", lambda e:callback("https://web.whatsapp.com/"))
text.pack(expand=1,fill=BOTH)
#Widgets
info_btn = Button(root,text="?",font=("Comic San MS",10,"bold"),command=user_info,bg="red").place(x=470,y=5)
ph_lbl = Label(root,text="Recipient's Whatsapp Number -",font=("Comic San MS",12,"bold"),bg="#33FF99").place(y=35,x=10)
v = StringVar()
v.set("")
h = DoubleVar()
m = DoubleVar()
phone_no = Entry(root,font=("Comic San MS",15,"bold"),textvariable = v,bg="white").place(x=270,y=35)
hrs_lbl = Label(root,text="Time(24 hr format)-" ,font=("Comic San MS",12,"bold"),bg="#33FF99").place(y=100,x=10)
hrs_entry = Scale(root,font=("Comic San MS",10,"bold"),variable = h,from_=1,to=24,orient=HORIZONTAL,bg="#33FF99",bd=0,label="hrs").place(x=230,y=80)
mins_entry = Scale(root,font=("Comic San MS",10,"bold"),variable = m,from_=1,to=60,orient=HORIZONTAL,bg="#33FF99",bd=0,label="mins").place(x=390,y=80)
msg_label = Label(root,text="Type your msg-",font=("Comic San MS",12,"bold"),bg="#33FF99").place(y=150,x=10)
msg_box = Text(root,height=10,width=40,font=("Comic San MS",11,"bold"))
msg_box.place(y=150,x=170)
error_lbl = Label(root,bg="#33FF99",font=("Comic San MS",12,"bold"),fg="red")
error_lbl.place(y=400,x=100)
def threading():
t = Thread(target=prt)
t.start()
def prt():
try:
int(v.get())
except:
error_lbl.config(text=" ERROR! Enter a valid ten digits Whatsapp number ")
if len(v.get()) != 10:
error_lbl.config(text="ERROR! Enter a valid ten digits Whatsapp number")
else:
import pywhatkit as kit
v_int = int(v.get())
kit.sendwhatmsg(f'+91{v_int}', msg_box.get(1.0,END), h.get() ,m.get(),tab_close=True,wait_time=5)
error_lbl.config(text=f'Msg has been sent to {v.get()} successfully')
def clr():
error_lbl.config(text="")
send_button = Button(root,text="Schedule to send message",font=("Comic San MS",11,"bold"),bg="lightgreen",command=threading).place(x=160,y=350)
error_clr = Button(root,text="CLEAR",font=("Comic San MS",10,"bold"),command=clr).place(y=460,x=220)
root.mainloop()
if is_connected():
main()
else:
con_check()
After converting your code into executable file, i ran the executable file on a terminal to find what is your real error:将您的代码转换为可执行文件后,我在终端上运行了该可执行文件以找出您真正的错误:
_tkinter.TclError: bitmap "whatsapp.ico" not defined
[10780] Failed to execute script (Your Script Name)
Simply you have a problem because of your icon, your icon isn't on the right path otherwise your code is working perfectly fine.只是您的图标有问题,您的图标不在正确的路径上,否则您的代码运行良好。
To fix this error just run your executable file while your icon on the right path, but if it still doesn't work:要修复此错误,只需在您的图标位于正确路径上时运行您的可执行文件,但如果它仍然不起作用:
from os import getcwd
.from os import getcwd
。root.iconbitmap("whatsapp.ico")
with root.iconbitmap(f"{getcwd()}\\\\whatsapp.ico")
root.iconbitmap(f"{getcwd()}\\\\whatsapp.ico")
替换这行代码root.iconbitmap("whatsapp.ico")
root.iconbitmap(f"{getcwd()}\\\\whatsapp.ico")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.