[英].exe from tkinter gui does not run (pyinstaller)
Reading a few threads helped me to create a.exe from my tkinter gui.阅读一些线程帮助我从我的 tkinter gui 创建 a.exe。
Unfortunately, nothing happens when I run the.exe file.不幸的是,当我运行 .exe 文件时没有任何反应。 The code runs normally, when I run it in vsc.
当我在 vsc 中运行代码时,代码运行正常。
Following the instructions online I did the following steps.按照网上的说明,我做了以下步骤。
cd filelocation
cd filelocation
移动到我的文件位置pyinstaller name-of-my-file.py
(also tried with the --onefile
specification for example.)pyinstaller name-of-my-file.py
(例如,也尝试了--onefile
规范。) As stated above, nothing happens when I run the.exe file.如上所述,当我运行 .exe 文件时没有任何反应。 Also tried running it as an administrator.
还尝试以管理员身份运行它。
Just in case, I will publish my code below.以防万一,我将在下面发布我的代码。
All kinds of help is appreciated.各种帮助表示赞赏。
from tkinter import *
from tkinter import messagebox
import time
import datetime
def clicked(event=None):
t = presentationDuration.get()
try:
t = float(t)
except ValueError:
messagebox.showerror(title='ValueError', message='The string is empty or there is no number entered!')
return
nSpeaker = nextSpeaker.get()
lbl.configure(text = nSpeaker, font = ("Arial Bold", 80))
t = int(t*60)
update(t)
def update(t):
if(t >= 0):
m,s = divmod(t, 60)
left_Time.configure(text = m)
right_Time.configure(text = s)
if(t <= 60):
nSpeaker = nextSpeaker.get()
lbl.configure(text = nSpeaker, bg = 'red', font = ("Arial Bold", 80))
window.after(1000, update, t-1)
window = Tk()
window.title("presenters Toolkit")
lbl_duration = Label(window, text = "duration [mins]")
lbl_duration.grid(column = 0, row = 0)
presentationDuration = Entry(window, width = 10)
presentationDuration.grid(column = 1, row = 0)
lbl_speaker = Label(window, text = "next Speaker")
lbl_speaker.grid(column = 2, row = 0)
nextSpeaker = Entry(window, width = 30)
nextSpeaker.grid(column = 3, row = 0)
lbl = Label(window, text = "", font = ("Arial Bold", 50))
lbl.grid(column = 1, row = 1)
btn = Button(window, text = "start", command = clicked)
btn.grid(column = 1, row = 3)
left_Time = Label(window, text ="--", font = ("Arial Bold", 80))
left_Time.grid(column = 0, row = 4)
mid_Time = Label(window, text = ":", font = ("Arial Bold", 80))
mid_Time.grid(column = 1, row = 4)
right_Time = Label(window, text = "--", font = ("Arial Bold", 80))
right_Time.grid(column = 2, row = 4)
window.mainloop()
You need to move the code of your functions above, so that their code goes, for example, after imports.您需要移动上面的函数代码,以便它们的代码例如在导入之后。 Also when running your code in the line
t = float(presentationDuration.get ())
, I found an error related to what if in t = float(presentationDuration.get())
empty, an exception is thrown when the button is clicked ValueError: could not convert string to float
.此外,当在
t = float(presentationDuration.get ())
行中运行代码时,我发现一个错误与如果在t = float(presentationDuration.get())
为空,单击按钮时抛出异常ValueError: could not convert string to float
。 So I would advise you to handle this situation.所以我建议你处理这种情况。 Below is the code as I would see the
clicked
function.下面是我会看到
clicked
的 function 的代码。 Sorry for my English, it's not my native language.对不起,我的英语不是我的母语。
def clicked(event=None):
t = presentationDuration.get()
try:
t = float(t)
except ValueError:
messagebox.showerror(title='ValueError', message='The string is empty or there is no number entered!') # also you should have such line in your code `from tkinter import messagebox`
return
nSpeaker = nextSpeaker.get()
lbl.configure(text = nSpeaker, font = ("Arial Bold", 80))
t = int(t*60)
update(t)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.