0

I am struggling ensure python script work on windows computer that does not have python installer. The script below only works on the computer with python software not sure where l am going wrong. Result is if uploaded on another computer no pictures or path is wrong. l am new to python can you please help as l dont know where l am going wrong. Thanks in advance

"""
from tkinter import*
import tkinter as tk
from tkinter import ttk
from datetime import datetime

windo = Tk()
windo.resizable(width=FALSE, height=FALSE)
windo.geometry("600x400")

windo.iconbitmap(r"C:\Users\breada\OneDrive\Desktop\Notes\image\Healthcare.ico") 
house = "Mhungu"



def han():
    print("Forms to be completed")
    import tkinter as tk
    from tkinter import ttk
    from datetime import datetime



    root = Tk()
    root.resizable(width=FALSE, height=FALSE)
    root.geometry("680x670")
    root.iconbitmap(r"C:\Users\breada\OneDrive\Desktop\Notes\image\Healthcare.ico") 

    house = "Mhungu"

    fun8 = Label(root, text="Running times comp  :")
    fun8.place(x=10,y=120)

    var32 = IntVar()
    chekbtn_1 = Checkbutton(root ,text="Yes", variable=var32)
    chekbtn_1.place(x=180,y=120)
    var33 = IntVar()
    chekbtn_2 = Checkbutton(root ,text="No", variable=var33)
    chekbtn_2.place(x=230,y=120)

    def cli(value):
        print("Severity of aggression")
        print(value)


    def clic(value):
        print("Area of aggression")
        print(value)


    def click(value):
        print("Nature of aggression")
        print(value)

    def save_funct():
        print("Saved")



       
    frame = LabelFrame(root, padx=5, pady=5)
    v = tk.StringVar()
    v.set("None")

    lab2 = Label(frame, text="Select Level of Aggression", fg="blue", font=("Arial", 10))
    lab2.pack()

    radioButton1 = Radiobutton(frame, variable=v,value="1-No Concern", text="1-No Concern", command=lambda:cli(v.get()))
    radioButton2 = Radiobutton(frame, variable=v, value="2-Not Severe",text="2-Not Severe",command=lambda:cli(v.get()) )
    radioButton3 = Radiobutton(frame, variable=v, value="3-Slightly Severe",text="3-Slightly Severe",command=lambda:cli(v.get()) )
    radioButton4 = Radiobutton(frame, variable=v, value="6-Extremely Severe",text="6-Extremely Severe",command=lambda:cli(v.get()) )
    radioButton5 = Radiobutton(frame, variable=v,value="5-Severe", text="5-Severe", command=lambda:cli(v.get()))
    radioButton6 = Radiobutton(frame, variable=v,value="4-Fairly Severe", text="6-Fairly Severe", command=lambda:cli(v.get()))
    radioButton1.pack(side=LEFT)
    radioButton2.pack(side=LEFT)
    radioButton3.pack(side=LEFT)
    radioButton4.pack(side=RIGHT)
    radioButton5.pack(side=RIGHT)
    radioButton6.pack(side=RIGHT)

    frame.place(x=35, y=155)

    frame1 = LabelFrame(root, padx=5, pady=5)
    vv = tk.StringVar()
    vv.set("None")

    lab2 = Label(frame1, text="Areas of Aggressions", fg="blue", font=("Arial", 10))
    lab2.pack()

    radioButton1 = Radiobutton(frame1, variable=vv,value="Lounge", text="Lounge", command=lambda:clic(vv.get()))
    radioButton2 = Radiobutton(frame1, variable=vv, value="Kitchen",text="Kitchen",command=lambda:clic(vv.get()) )
    radioButton3 = Radiobutton(frame1, variable=vv, value="Bedroom 1",text="Bedroom 1",command=lambda:clic(vv.get()) )
    radioButton4 = Radiobutton(frame1, variable=vv, value="Bedroom 2",text="Bedroom 2",command=lambda:clic(vv.get()) )
    radioButton5 = Radiobutton(frame1, variable=vv,value="Bedroom 3", text="Bedroom 3", command=lambda:clic(vv.get()))
    radioButton6 = Radiobutton(frame1, variable=vv,value="Dinning ", text="Dinning", command=lambda:clic(vv.get()))
    radioButton1.pack(side=LEFT)
    radioButton2.pack(side=LEFT)
    radioButton3.pack(side=LEFT)
    radioButton4.pack(side=RIGHT)
    radioButton5.pack(side=RIGHT)
    radioButton6.pack(side=RIGHT)

    frame1.place(x=35, y=255)

    frame2 = LabelFrame(root, padx=5, pady=5)
    vvv = tk.StringVar()
    vvv.set("None")

    lab2 = Label(frame2, text="Nature of Aggression", fg="blue", font=("Arial", 10))
    lab2.pack()

    radioButton1 = Radiobutton(frame2, variable=vvv,value="Punching", text="Punching", command=lambda:click(vvv.get()))
    radioButton2 = Radiobutton(frame2, variable=vvv, value="Kicking",text="Kicking",command=lambda:click(vvv.get()) )
    radioButton3 = Radiobutton(frame2, variable=vvv, value="Pushing ",text="Pushing",command=lambda:click(vvv.get()) )
    radioButton4 = Radiobutton(frame2, variable=vvv, value="Forceful",text="Forceful",command=lambda:click(vvv.get()) )
    radioButton5 = Radiobutton(frame2, variable=vvv,value="Punching Walls", text="Punching Walls", command=lambda:click(vvv.get()))
    radioButton6 = Radiobutton(frame2, variable=vvv,value="Clinch fists ", text="Clinch fists", command=lambda:click(vvv.get()))
    radioButton1.pack(side=LEFT)
    radioButton2.pack(side=LEFT)
    radioButton3.pack(side=LEFT)
    radioButton4.pack(side=RIGHT)
    radioButton5.pack(side=RIGHT)
    radioButton6.pack(side=RIGHT)

    frame2.place(x=35, y=355)

    buttnn = Button(root, text="Save", width=10, height=2, fg= "blue",command=save_funct)
    buttnn.place(x=570, y=615)

    root.mainloop()

def st_ii():
    print("Redirected")

canvas=Canvas(width=400,height=200, bg="blue")
canvas.place(x=200,y=130)
photo=PhotoImage(file="C:\\Users\\breada\\OneDrive\\Desktop\\Forest.png")
canvas.create_image(0,0,image=photo, anchor=NW)


toolbar = Frame(windo, bg="powder blue", padx=3, pady=20)
insertButt= Button(toolbar,text = "A-Form",command =han)
insertButt.pack(side=LEFT, padx=6,pady=2)
shift_planButt = Button(toolbar, text= "B-Form",command =st_ii)
shift_planButt.pack(side=LEFT, padx=6,pady=2)



toolbar.pack(side=TOP,fill=X)


windo.mainloop()



"""
  • What have you tried? What have you searched for? – GordonAitchJay Aug 23 '22 at 12:32
  • Thank very much for your response, the EXE script works on a computer with python compiler and does not work on computer without python script although the window comes on with missing pictures and icons. I have used pyinstaller to turn the script into EXE file. It works on the computer on which the script was complied only. – Muss mhaka Aug 23 '22 at 13:12
  • Okay I see. You need to [pack](https://pyinstaller.org/en/stable/usage.html#cmdoption-add-data) those image/icon files when you use PyInstaller. Then edit your script so when you read those files you get their filepaths with [`resource_path()`](https://stackoverflow.com/a/13790741/3589122). – GordonAitchJay Aug 23 '22 at 13:39
  • Thank you very much for your help, l will do as you have instructed, l really appreciate – Muss mhaka Aug 23 '22 at 13:41

1 Answers1

0

If you compile your script into an executable file, for example by using "auto-py-to-exe", then the resulting .exe-file can be run on any computer with the same architecture as the one you created the .exe file on.

You can include other files or folders containing pictures or icons using a simple GUI.

you can install it with pip:

$ pip install auto-py-to-exe

or directly from github: https://github.com/brentvollebregt/auto-py-to-exe

Schpenn
  • 108
  • 1
  • 11
  • Thank you, l will look at the link as above, the EXE script works on a computer with python compiler and does not work on computer without python script although the window comes on with missing pictures and icons – Muss mhaka Aug 23 '22 at 13:09