0

There are some files that open with double click . But not this one . I want to open it with double click . it has the following code written inside it:

from tkinter import*
tk=Tk()
tk.title("App Manager")
tk.resizable(0,0)
tk.wm_attributes("-topmost",1)
canvas=Canvas(tk,width=460,height=500,bg='black',bd=0,highlightthickness=0)
canvas.pack()
tk.update()
def pong():
    tk.destroy()
    import PONG
def bounce():
    tk.destroy()
    import BOUNCE
def calculator():
    import CALCULATOR
def quit1():
    tk.destroy()
b1=Button(tk,text="Play PONG",font= ('Bold',15),bg='brown',fg='gold',command=pong)
b1.pack(side=LEFT)
b2=Button(tk,text="Play BOUNCE",font=('Bold',15),bg='brown',fg='gold',command=bounce)
b2.pack(side=LEFT)
b3=Button(tk,text="CALCULATOR",font=('Bold',15),bg='brown',fg='gold')
b3.pack(side=LEFT)
b4=Button(tk,text="Quit",font=('Bold',15),bg='brown',fg='gold',command=quit1)
b4.pack(side=RIGHT)
KAR PAT
  • 1
  • 1
  • Possible duplicate of [Python script doesn't work with double click](http://stackoverflow.com/questions/18234908/python-script-doesnt-work-with-double-click) – JazZ Aug 21 '16 at 18:31

3 Answers3

0

Rename the file and give it a .py extension. You may have to disable "Hide extensions for known file types" under folder properties.

Tasos Papastylianou
  • 21,371
  • 2
  • 28
  • 57
0

If you want it to run on the double click on any other computer, there is a package called Pyinstaller that will compile a python script with its dependencies so that it can be opened with a double-click and run on any system.

However, it will only run on the same operating system that it was compiled on. So if you want it to run on a windows system it must be compiled on a windows system.

http://www.pyinstaller.org/ check it out.

beerandsmiles
  • 134
  • 3
  • 12
0

I found the answer myself. The easiest way to open a file.py extension through double click is to add init() function in a class. Just create a class with init() function. That will make every file.py open with double click.

KAR PAT
  • 1
  • 1
  • please see this as constructive criticism on how to use the site better, rather than a personal attack, but that was a horrible question and a waste of people's time. First of all, opening files on double click using the appropriate program is the operating system's job; there's nothing you could add "inside" the file to change that (except for a "crunchbang" syntax on Unix systems which is specifically designed to direct the OS to the correct interpreter, but as far as I'm aware this does not occur on windows, and windows relies specifically on the file extension). – Tasos Papastylianou Aug 24 '16 at 09:42
  • Which means your file was already opening and specifically it was opening in the python interpreter, and what you really meant to ask is why you don't see the intended result. Secondly, there's no `init()` function, presumably you mean the `__init__()` function which is specific to object oriented contexts. Which means you didn't even tell us you were dealing with a class! Thirdly, `__init__()` won't do what you said either. You probably added a "__main__" boilerplate and you didn't notice. No wonder you got rubbish answers. – Tasos Papastylianou Aug 24 '16 at 09:42
  • I added the class later on to add __init__() and make double click work . – KAR PAT Aug 25 '16 at 23:11