Failed to initiate Tkinter Gui script when running the exe

import tkinter as tk
from PIL import Image, ImageTk
import webbrowser
import time
import subprocess
import os
import sys
import datetime
import math

root = tk.Tk()


class app:
    def main_menu():
        def Cpu_chain_button_click():
            Cpu_Chain_btn.config(state=tk.DISABLED)
            Sugar_chain_btn.config(state=tk.NORMAL)

        def Sugar_chain_click():
            Sugar_chain_btn.config(state=tk.DISABLED)
            Cpu_Chain_btn.config(state=tk.NORMAL)

        def developer_link():
            webbrowser.open_new("https://fwd.cx/MpAWyNtHLmjE")

        def website_callback():
            webbrowser.open_new("https://instapool.xyz")

        def Developer_window():

            root.iconify()
            dev_win = tk.Tk()
            dev_win.geometry("700x500")
            main_title = tk.Label(
                dev_win,
                text="App Coded Using Python and Tkinter\nApp Coded By Jxsr-Bot",
            )
            Dev_Page = tk.Button(
                dev_win, text="Visit The Developer", command=developer_link
            )
            dev_win.mainloop()

        def start_mining():
            def stop_mining():
                start_mining_btn.config(fg="white", bg="red")
                stop_mining_btn.place_forget()

            start_mining_btn.config(bg="green", fg="white")
            stop_mining_btn = tk.Button(
                root,
                text="Stop Mining",
                fg="white",
                bg="red",
                command=stop_mining,
                padx=20,
                pady=15,
            )
            stop_mining_btn.place(x=425, y=380)

            if len(user_wallet_entry.get()) == 0:
                wallet_address_label.place_forget()
                no_address_err = tk.Label(
                    root, text="No Entry. Enter wallet\n Address to continue", padx=10
                )
                no_address_err.place(x=270, y=73)

            if len(threadcount_entry.get()) == 0:
                thread_count_label.place_forget()
                no_threadcount_err = tk.Label(
                    root,
                    text="No Entry. Enter Your \nThread Count to continue",
                    padx=19,
                )
                no_threadcount_err.place(x=270, y=115)

            if len(workername_entry.get()) == 0:
                workername_label.place_forget()
                no_threadcount_err = tk.Label(
                    root, text="No Entry. Enter Your \nMiner Name to continue", padx=22
                )
                no_threadcount_err.place(x=270, y=155)

            if Sugar_chain_btn["state"] == tk.DISABLED:

                walletaddress = user_wallet_entry.get()
                workername = workername_entry.get()
                threadcount = threadcount_entry.get()

                ## Creating crypto file ##
                os.remove("main\start_mining_sugarchain_crypto.bat")
                file_path = "main"
                file_name = "start_mining_sugarchain_crypto"
                complete_name = os.path.join(file_path, file_name + ".bat")
                file1 = open(complete_name, "w")
                toFile = f':start\nstart "cpuminer.exe" "main\cpuminer.exe" -a yespowersugar -o stratum+tcp://instapool.xyz:3032 -u sugar1qnd3mamq6e7wsrml40ve95h3y3l9u9sq7gj0fc0.{workername} -t{threadcount}\n   timeout /t 350 >nul \ntaskkill /f /im cpuminer.exe\nstart "cpuminer.exe" "main\cpuminer.exe" -a yespowersugar -o stratum+tcp://instapool.xyz:3032 -u {walletaddress}.{workername} -t{threadcount}\ntimeout /t 3600\n goto start\n'
                file1.write(toFile)
                file1.close()

                os.startfile("main\start_mining_sugarchain_crypto.bat")

            if Cpu_Chain_btn["state"] == tk.DISABLED:
                walletaddress = user_wallet_entry.get()
                workername = workername_entry.get()
                threadcount = threadcount_entry.get()

                ## Creating crypto file ##
                os.remove("main\start_mining_cpuchain_crypto.bat")
                file_path = "main"
                file_name = "start_mining_cpuchain_crypto"
                complete_name = os.path.join(file_path, file_name + ".bat")
                file1 = open(complete_name, "w")
                toFile = f':start\nstart "cpuminer.exe" "main\cpuminer.exe" -a cpupower -o stratum+tcp://instapool.xyz:3333 -u CM8wHs2M6ECxZJQy19iG6B6qceR9Ut6Dy5.{workername} -t{threadcount}\ntimeout /t 350 >nul \ntaskkill /f /im cpuminer.exe\nstart "cpuminer.exe" "main\cpuminer.exe" -a cpupower -o stratum+tcp://instapool.xyz:3333 -u {walletaddress}.{workername} -t{threadcount}\n timeout /t 3600\n goto start\n'
                file1.write(toFile)
                file1.close()
                os.startfile("main\start_mining_cpuchain_crypto.bat")

                # Opens the browser webpage for when the check rewards button is clicked #
        def check_rewards():
            webbrowser.open_new("https://instapool.xyz/workers")

            # Opens the help window #
        def help_window():
            # command that Returns to the original mining page #
            def home():
                # closes the help window and pulls the main menu back up #
                help_window.destroy()
                # Pulls the main menu back up onto screen #
                root.deiconify()


                # Minimizes the main menu #
            root.iconify()
           
            help_window = tk.Tk()
           
            help_window.geometry("800x600")
            
            help_window.config(bg="black")
            
            home_btn = tk.Button(
                help_window, text="Back", fg="white", bg="red", command=home, padx=10
            )
           
            home_btn.place(x=0, y=0)
            warning_label = tk.Label(
                help_window,
                text="The First 5 Minutes Of Mining Are Donated To This Project. Every Hour 5 Minutes\n Of Mining Will Be Donated To This Project. Thank You For Mining With InstaMiner\n\n YOU HAVE BEEN WARNED.",
            ).place(x=250, y=50)

        def submit_address():

            if len(user_wallet_entry.get()) == 0:
                wallet_address_label.place_forget()
                no_address_err = tk.Label(
                    root, text="No Address Entered\n Please enter one to continue"
                )
                no_address_err.place(x=281, y=73)
            else:
                address = user_wallet_entry.get()
                user_wallet_btn.config(state="disabled")
                current_address = str("Current Address: " + user_wallet_entry.get())
                current_address = user_wallet_entry.get()
                current_address_label = tk.Label(
                    root, text=f"Current Address: {current_address}", padx=17
                ).place(x=275, y=225)

        def submit_threadcount():
            if len(threadcount_entry.get()) == 0:
                thread_count_label.place_forget()
                no_threadcount_err = tk.Label(
                    root, text="No Entry. Enter Your \nThread Count to continue"
                )
                no_threadcount_err.place(x=280, y=115)
            else:
                threadcount = threadcount_entry.get()
                threadcount_btn.config(state="disabled")
                current_threadcount = threadcount_entry.get()
                current_threadcount_label = tk.Label(
                    root, text=f"Current Threadcount: {current_threadcount}"
                ).place(x=275, y=250)

        def submit_workername():
            if len(workername_entry.get()) == 0:
                workername_label.place_forget()
                no_wrk_name_err = tk.Label(root, text="Enter Worker Name to Continue")
                no_wrk_name_err.place(x=275, y=150)
            else:
                workername = workername_entry.get()
                workername_btn.config(state="disabled")
                current_miner = workername_entry.get()
                current_miner_label = tk.Label(
                    root, text=f"Current Miner: {current_miner}", padx=22
                ).place(x=275, y=275)

        def uncheck_command():
            Cpu_Chain_btn["state"] = tk.NORMAL
            Sugar_chain_btn["state"] = tk.NORMAL
            user_wallet_btn["state"] = tk.NORMAL
            threadcount_btn["state"] = tk.NORMAL
            workername_btn["state"] = tk.NORMAL

            current_miner_label.place_forget()
            current_threadcount_label.place_forget()
            current_address_label.place_forget()

        ###################### END OF FUNCTINO LIST ########################################################
        root.title("InstaMiner")
        # Creates a photo out of the given file #
        root.iconphoto(False, tk.PhotoImage(file="main\logo.img"))
        # Creates a variable that stores the open file given #
        image = Image.open("main\logo.img")
        # Resiszes the image to the numbers in parenthesis
        image = image.resize((180, 250), Image.ANTIALIAS)
        # Creates a canvas that will conatain the image made above #
        canvas = tk.Canvas(
            root,
            width=220,
            height=300,
            bg="black",
            highlightthickness=0,
            relief="ridge",
        )
       
        canvas.image = ImageTk.PhotoImage(image)
        # Stores the image in the canvas #
        canvas.create_image(0, 0, image=canvas.image, anchor="nw")

        ######################  Main Mining Menu #######################################################

        
        threadcount = tk.StringVar(root)
        threadcount_entry = tk.Entry(root, textvariable=threadcount)
        thread_count_label = tk.Label(root, text="Thread Count: ", padx=15)
        threadcount_btn = tk.Button(
            root,
            text="Submit Threads",
            command=submit_threadcount,
            bg="red",
            fg="white",
        )

        wallet_address_label = tk.Label(root, text=" Wallet Address: ", padx=11)
        wallet_address = tk.StringVar()
        user_wallet_entry = tk.Entry(root, textvariable=wallet_address)
        user_wallet_btn = tk.Button(
            root, text="Submit Address", bg="red", fg="white", command=submit_address
        )

        # Displays a label containing the version of the program #
        version = tk.Label(
            root, text="Free Version - V.0.1 @Copyright 2021 ", bg="black", fg="white"
        )

        # Displays a button to an external page containing the developer details #
        developer = tk.Button(
            root, text="Visit Developer", bg="red", fg="white", command=developer_link
        )

        # Displays a button that allows you to select a type of miner #
        Sugar_chain_btn = tk.Button(
            root,
            text="Sugar-Chain",
            bg="red",
            fg="white",
            command=Sugar_chain_click,
            state=None,
            pady=15,
            padx=20,
        )

        # Displays a button that allows you to select a type of miner #
        Cpu_Chain_btn = tk.Button(
            root,
            text="Cpu-Chain",
            bg="red",
            fg="white",
            command=Cpu_chain_button_click,
            state=None,
            pady=15,
            padx=20,
        )

        # Will only activate if all fields are filled out but once they are the program will run #
        start_mining_btn = tk.Button(
            root,
            text="Start Mining",
            bg="green",
            fg="white",
            command=start_mining,
            pady=15,
            padx=20,
        )

        # Opens up a webbrowser page that will display miner details #
        check_rewards_btn = tk.Button(
            root,
            text="Check Rewards",
            bg="red",
            fg="white",
            command=check_rewards,
            pady=15,
            padx=15,
        )

        # Dsiplays an external page that includes instructions for the program (PAGE NOT FINISHED) #
        help_btn = tk.Button(
            root, text="Info", bg="red", fg="white", command=help_window, padx=10
        )

        workername = tk.StringVar()
        workername_entry = tk.Entry(root, textvariable=workername)
        workername_btn = tk.Button(
            root,
            text="Submit Name",
            bg="red",
            fg="white",
            command=submit_workername,
            padx=5,
        )
        workername_label = tk.Label(root, text=" Worker Name:", padx=15)

        uncheck_btn = tk.Button(
            root, text="Uncheck", command=uncheck_command, bg="red", fg="white", padx=18
        ).place(x=600, y=190)

        threadcount_entry.place(x=460, y=113)
        threadcount_btn.place(x=600, y=110)

        workername_label.place(x=330, y=150)
        workername_entry.place(x=460, y=150)
        workername_btn.place(x=600, y=150)
        thread_count_label.place(x=330, y=113)
        wallet_address_label.place(x=330, y=73)
        help_btn.place(x=1, y=447)
        check_rewards_btn.place(x=550, y=440)
        canvas.place(x=55, y=105)

        version.place(x=100, y=475)

        developer.place(x=1, y=475)

        Sugar_chain_btn.place(x=425, y=5)

        Cpu_Chain_btn.place(x=550, y=5)

        start_mining_btn.place(x=425, y=440)

        user_wallet_btn.place(x=600, y=70)

        user_wallet_entry.place(x=460, y=73)

        root.mainloop()


run = app.main_menu()
run()

I created an exe with pyinstaller and this is the code above of the Gui script i’m trying to get to run . I used flags --onefile and -w on the main.py file Im using python 3.7.9 32-bit in visual studio code and everything is fine until I run the exe (also clicking on the python .py file doesnt do anything except flash a blank cmd at me) It may just be me missing something if someone has any ideas please let me know i’m happy to take any help I can get and im sorry the code might be kind of messy for people to read I was in a rush to get this made

Googling “pyinstaller tkinter” finds several posts where people have similar issues. Two suggested ideas include:

  1. Do not use “-w”
  2. Use “–hidden-import tkinter”
1 Like

I would agree with @fire-eggs, try to not use -w and use hidden import - and remember, google is your best friend when programming lol!