简体   繁体   中英

.exe from tkinter gui does not run (pyinstaller)

Reading a few threads helped me to create a.exe from my tkinter gui.

Unfortunately, nothing happens when I run the.exe file. The code runs normally, when I run it in vsc.

Following the instructions online I did the following steps.

  1. I opened the command prompt, moved to my file location with cd filelocation
  2. I ran the command pyinstaller name-of-my-file.py (also tried with the --onefile specification for example.)
  3. I get three folders pycache, dist and build, and within build I find the respective.exe file.

As stated above, nothing happens when I run the.exe file. 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 . So I would advise you to handle this situation. Below is the code as I would see the 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM