转换后我的exe文件不起作用
我在Python中使用了数字时钟脚本,并尝试使用Pyinstaller将其转换为.exe文件/应用,如下所示:
pyinstaller --onedir --onefile clock1.py
我也尝试过
pyinstaller --onefile clock1.py
,我
pyinstaller -w --onefile clock1.py
也尝试了它,现在我也尝试了它编译。...显然没有任何问题... 但是,当我尝试运行它时,什么也不会发生……甚至没有错误消息。
这是python文件:(感谢教程和代码编程)
from tkinter import *
from datetime import datetime
from time import strftime
from PIL import ImageTk, Image
def main():
pass
root = Tk()
root.geometry('1280x720')
root.minsize(820,200)
root.title("Digital Clock")
# SETTING BACKGROUND
img1=Image.open("g3.jpg")
img2=ImageTk.PhotoImage(img1)
Label(root, image=img2).place(x=0,y=2)
f1=Frame(root, width=820, height=200, bg="#0E1013")
#f1.place(x=0, y=0)
f1.pack(expand=True)
a=datetime.today().strftime("%A")
b=a.upper()
c=b[0:2]
def time():
a=strftime("%H : %M : %S")
l1.config(text=a)
l1.after(1000, time)
l1=Label(f1, font=("Century Gothic", 60), bg="#0E1013", foreground="#D3D3D3")
l1.place(x=300, y=15)
time()
l2=Label(f1, font=("Century Gothic", 60), bg="#0E1013", foreground="#D3D3D3")
l2.config(text=c+" |")
l2.place(x=80, y=15)
def labels():
l3=Label(f1, font=("Century Gothic", 12), bg="#0E1013", fg="#D3D3D3", text = "DAY")
l3.place(x=90, y=130)
l4=Label(f1, font=("Century Gothic", 12), bg="#0E1013", fg="#D3D3D3", text = "HOURS")
l4.place(x=320, y=130)
l5=Label(f1, font=("Century Gothic", 12), bg="#0E1013", fg="#D3D3D3", text = "MINUTES")
l5.place(x=510, y=130)
l6=Label(f1, font=("Century Gothic", 12), bg="#0E1013", fg="#D3D3D3", text = "SECONDS")
l6.place(x=705, y=130)
labels()
#root.mainloop()
if __name__ == "__main__":
main()
这是 g3.img3
用于背景的图像文件。
如果要添加图像以使其运行,只需创建一个并将其称为g3.img
python脚本运行良好...只是想知道为什么在将其转换为EXE并试图运行它之后,我什么也没得到...然后,我确实将图像文件复制到了DIST文件夹之后。
I have used a digital clock script in Python, and I tried to convert it to an .exe file/app using pyinstaller as follows:
pyinstaller --onedir --onefile clock1.py
and I also tried
pyinstaller --onefile clock1.py
and I also tried
pyinstaller -w --onefile clock1.py
Now it compiles....without any issues apparently...
But when I try to run it, nothing happens...not even an error message.
Here is the python file: (thanks to PROGRAMMED for the tutorial and code)
from tkinter import *
from datetime import datetime
from time import strftime
from PIL import ImageTk, Image
def main():
pass
root = Tk()
root.geometry('1280x720')
root.minsize(820,200)
root.title("Digital Clock")
# SETTING BACKGROUND
img1=Image.open("g3.jpg")
img2=ImageTk.PhotoImage(img1)
Label(root, image=img2).place(x=0,y=2)
f1=Frame(root, width=820, height=200, bg="#0E1013")
#f1.place(x=0, y=0)
f1.pack(expand=True)
a=datetime.today().strftime("%A")
b=a.upper()
c=b[0:2]
def time():
a=strftime("%H : %M : %S")
l1.config(text=a)
l1.after(1000, time)
l1=Label(f1, font=("Century Gothic", 60), bg="#0E1013", foreground="#D3D3D3")
l1.place(x=300, y=15)
time()
l2=Label(f1, font=("Century Gothic", 60), bg="#0E1013", foreground="#D3D3D3")
l2.config(text=c+" |")
l2.place(x=80, y=15)
def labels():
l3=Label(f1, font=("Century Gothic", 12), bg="#0E1013", fg="#D3D3D3", text = "DAY")
l3.place(x=90, y=130)
l4=Label(f1, font=("Century Gothic", 12), bg="#0E1013", fg="#D3D3D3", text = "HOURS")
l4.place(x=320, y=130)
l5=Label(f1, font=("Century Gothic", 12), bg="#0E1013", fg="#D3D3D3", text = "MINUTES")
l5.place(x=510, y=130)
l6=Label(f1, font=("Century Gothic", 12), bg="#0E1013", fg="#D3D3D3", text = "SECONDS")
l6.place(x=705, y=130)
labels()
#root.mainloop()
if __name__ == "__main__":
main()
Here's the g3.img
image file used for background.
If you want to add an image to make it run, just create one and call it g3.img
The python script runs fine...just wondering why I get nothing after converting it to an EXE and trying to run it...oh and I did copy the image file to the DIST folder after I made the EXE file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定只需运行它而不将其转换为.exe文件,它是否有效?
您应该取消主题循环:
而不是
因为此行实际运行GUI,而是其他行只是定义它。
Are you sure it works if you just run it without converting it to .exe file?
You should uncomment the main loop:
instead of
because this line actually runs the GUI, other lines just define it.