79299110

Date: 2024-12-21 08:53:23
Score: 0.5
Natty:
Report link

acw1668 told to read https://pyinstaller.org/en/stable/runtime-information.html
Using that , i changed tkinter code to following

import tkinter as tk
import sys
from os import path
class Application(tk.Tk):
    def __init__(self, title:str="Simple", x:int=0, y:int=0, **kwargs):
        tk.Tk.__init__(self)
        self.title(title)
        self.config(**kwargs)
        #
        if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
            print('running in a PyInstaller bundle')
        else:
            print('running in a normal Python process')
        self.first_row_frame=tk.Frame(self)
        path_to_dat = path.abspath(path.join(path.dirname(__file__),'icofolder'))
        print(path_to_dat)
        self.iconbitmap(path_to_dat+'\\icon.ico')
        self.first_row_frame.grid(column=0,row=0,sticky='W')
        self.lbl_ser_num=tk.Label(self.first_row_frame,text="Sr No:",font='Arial 50 bold')
        self.lbl_ser_num.grid(column=0,row=0)
        self.update_idletasks()
        self.state('zoomed')

if __name__ == "__main__":
    # height of 0 defaults to screenheight, else use height
    Application(title="simple app").mainloop()

Then I created exe using following command

pyinstaller --clean --onefile -i "icon.ico" --add-data "icon.ico;icofolder" my-script.py

Then you simply run exe file of dist folder from anywhere.

Now only thing is that icon is blurry though my icon is 184x256 pixel as per mspaint.
Thanks.

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: lxuser