Page 1 of 1

python tkinter wont run as executable

Posted: Mon Aug 06, 2018 6:26 pm
by craig196
Hi,
I've created a py/Tkinter module that I can double-click in windows, but it does nothing in Linux Cinnamon 17.3 2.8.8.
it runs ok in idle3 but I cant make it "Double-clickable" , it just opens and shuts immediately.

#!/usr/bin/env python3.4

import time
import tkinter as tk

window = tk.Tk()
window.title("Water Ratio calculator")
window.geometry("350x200")
#--- functions
def calc_out():
volume =int(entry_vol.get())
tankTemp =int(entry_tt.get())
coldTemp =int(entry_ct.get())

#calculation
hot_supply_temp=100
hot_required=volume/(((tankTemp-coldTemp)/(hot_supply_temp-tankTemp)*7)+7)*((tankTemp-coldTemp)/(hot_supply_temp-tankTemp)*7)
cold_required=volume/(((tankTemp-coldTemp)/(hot_supply_temp-tankTemp)*7)+7)*7

#cold_output1
cold_label=tk.Label(text="Cold required")
cold_label.grid(column=0,row=5,sticky="w")
coldisplay=tk.Text(master=window,height=1,width=5)
coldisplay.grid(column=0,row=5,sticky="e")
coldisplay.insert(tk.END,cold_required)

#hot_output1
hot_label=tk.Label(text="Hot required")
hot_label.grid(column=0,row=6,sticky="w")
hotout=tk.Text(master=window,height=1,width=5)
hotout.grid(column=0,row=6,sticky="e")
hotout.insert(tk.END,hot_required)
#end of function


#label
title = tk.Label(text="My Water Calculator App",font=("Times New Roman",20))
title.grid(column=0,row=0)

#volume
volume = tk.Label(text="How much are you changing",)
volume.grid(column=0,row=1,sticky="w")

#entry field
entry_vol=tk.Entry(width=5)
entry_vol.grid(column=1,row=1)


#tank temp
tanktemp = tk.Label(text="What is the tank temperature?")
tanktemp.grid(column=0,row=2,sticky="w")


#entry field
entry_tt=tk.Entry(width=5)
entry_tt.grid(column=1,row=2)

#cold temp
coldtemp = tk.Label(text="What is the Cold water temperature?")
coldtemp.grid(column=0,row=3,sticky="w")

#entry field
entry_ct=tk.Entry(width=5)
entry_ct.grid(column=1,row=3)


#button
run=tk.Button(text="Run",bg="blue",command=calc_out )

run.grid(column=0,row=4,sticky="w")





window.mainloop()

Re: python tkinter wont run as executable

Posted: Mon Aug 06, 2018 7:47 pm
by rene
If you post code, any code but certainly indentation-sensitive Python code, please do so within [code] and [/code] tags.

Other than that: works for me on 18.3 after changing #!/usr/bin/env python3.4 to #!/usr/bin/env python3; the Python 3 version on 18.3 is 3.5. Although I do recall that it was 3.4 on Mint 17 indeed, what happens if you change likewise? Because that seems to be really the only difference between idle3- and commandline/doubleclick-invocation: idle3 invokes python3.

Do you even have a /usr/bin/python3.4 binary/link? You should, but maybe you installed something manually. Having idle3 installed does mean you have tk installed as well, so nothing else comes to mind.

Does python3.4 /where/ever/Water_Ratio.py from the command line work? python3 /where/ever/Water_Ratio.py? /where/ever/Water_Ratio.py?

[EDIT] This:

Code: Select all

#calculation
hot_supply_temp=100
hot_required=volume/(((tankTemp-coldTemp)/(hot_supply_temp-tankTemp)*7)+7)*((tankTemp-coldTemp)/(hot_supply_temp-tankTemp)*7)
cold_required=volume/(((tankTemp-coldTemp)/(hot_supply_temp-tankTemp)*7)+7)*7
would by the way seem to lend itself nicely to being optimized to

Code: Select all

#calculation
hot_supply_temp=100
cold_required=volume*(hot_supply_temp-tankTemp)/(hot_supply_temp-coldTemp)
hot_required=volume-cold_required
I.e., what is that weird factor 7 you have in there? Mathematically it just drops out.

Re: python tkinter wont run as executable

Posted: Tue Aug 07, 2018 6:42 am
by craig196
Hi,
I appear to have sorted it. Just double clicking the file just gives the option[img] [Run in Terminal]:[Display]:[Cancel]:[Run]. But if I create a desktop launcher and put the path of the file in the command then it works. Dont put a x in " [ ] Launch in Terminal"

Re: python tkinter wont run as executable

Posted: Tue Aug 07, 2018 6:51 am
by rene
craig196 wrote:
Tue Aug 07, 2018 6:42 am
Just double clicking the file just gives the option [Run in Terminal]:[Display]:[Cancel]:[Run].
You originally said that "it just opens and shuts immediately". The dialogue behaviour you now describe is as expected and can be set in the file manager's Edit -> Preferences -> Behaviour -> "Executable Text Files".