calling a python script on button click using python and tkinter












9















I have a python script which has the functionality of sending an email to a user. I executed this script and it is working fine. In another python script I have only a button, so when I click on this button I want the other python script which sends a email to be executed.I have written the following code:



#!/usr/bin/python
import sys
import os
import Tkinter
import tkMessageBox
top=Tkinter.Tk()

def helloCallBack():
os.system('SendEmail.py')

B=Tkinter.Button(top,text="hello",command= helloCallBack)
B.pack()
top.mainloop()


I get the following error when I click on the button:



sh: 1:SendEmail.py:not found.



Could you let me know what is the reason for this error and how it can be resolved.Thanks.










share|improve this question























  • If you go to a command prompt and type SendEmail.py, what happens? Do you get the same error?

    – Bryan Oakley
    Nov 10 '14 at 20:44











  • no it works fine.I executed the same python file separately and then it worked fine.I used python SendEmail.py and it worked.

    – Valla
    Nov 10 '14 at 20:53






  • 1





    Do you notice what you just wrote? You said "I used python SendEmail.py". That's not what I asked, and that's not what you're doing in the script. At a prompt, type literally SendMail.py not python SendMail.py. I suspect you'll get the same error. If it doesn't work from the command line, it's not going to work from os.system().

    – Bryan Oakley
    Nov 10 '14 at 20:55


















9















I have a python script which has the functionality of sending an email to a user. I executed this script and it is working fine. In another python script I have only a button, so when I click on this button I want the other python script which sends a email to be executed.I have written the following code:



#!/usr/bin/python
import sys
import os
import Tkinter
import tkMessageBox
top=Tkinter.Tk()

def helloCallBack():
os.system('SendEmail.py')

B=Tkinter.Button(top,text="hello",command= helloCallBack)
B.pack()
top.mainloop()


I get the following error when I click on the button:



sh: 1:SendEmail.py:not found.



Could you let me know what is the reason for this error and how it can be resolved.Thanks.










share|improve this question























  • If you go to a command prompt and type SendEmail.py, what happens? Do you get the same error?

    – Bryan Oakley
    Nov 10 '14 at 20:44











  • no it works fine.I executed the same python file separately and then it worked fine.I used python SendEmail.py and it worked.

    – Valla
    Nov 10 '14 at 20:53






  • 1





    Do you notice what you just wrote? You said "I used python SendEmail.py". That's not what I asked, and that's not what you're doing in the script. At a prompt, type literally SendMail.py not python SendMail.py. I suspect you'll get the same error. If it doesn't work from the command line, it's not going to work from os.system().

    – Bryan Oakley
    Nov 10 '14 at 20:55
















9












9








9


1






I have a python script which has the functionality of sending an email to a user. I executed this script and it is working fine. In another python script I have only a button, so when I click on this button I want the other python script which sends a email to be executed.I have written the following code:



#!/usr/bin/python
import sys
import os
import Tkinter
import tkMessageBox
top=Tkinter.Tk()

def helloCallBack():
os.system('SendEmail.py')

B=Tkinter.Button(top,text="hello",command= helloCallBack)
B.pack()
top.mainloop()


I get the following error when I click on the button:



sh: 1:SendEmail.py:not found.



Could you let me know what is the reason for this error and how it can be resolved.Thanks.










share|improve this question














I have a python script which has the functionality of sending an email to a user. I executed this script and it is working fine. In another python script I have only a button, so when I click on this button I want the other python script which sends a email to be executed.I have written the following code:



#!/usr/bin/python
import sys
import os
import Tkinter
import tkMessageBox
top=Tkinter.Tk()

def helloCallBack():
os.system('SendEmail.py')

B=Tkinter.Button(top,text="hello",command= helloCallBack)
B.pack()
top.mainloop()


I get the following error when I click on the button:



sh: 1:SendEmail.py:not found.



Could you let me know what is the reason for this error and how it can be resolved.Thanks.







python-2.7 tkinter






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 '14 at 20:31









VallaValla

93242752




93242752













  • If you go to a command prompt and type SendEmail.py, what happens? Do you get the same error?

    – Bryan Oakley
    Nov 10 '14 at 20:44











  • no it works fine.I executed the same python file separately and then it worked fine.I used python SendEmail.py and it worked.

    – Valla
    Nov 10 '14 at 20:53






  • 1





    Do you notice what you just wrote? You said "I used python SendEmail.py". That's not what I asked, and that's not what you're doing in the script. At a prompt, type literally SendMail.py not python SendMail.py. I suspect you'll get the same error. If it doesn't work from the command line, it's not going to work from os.system().

    – Bryan Oakley
    Nov 10 '14 at 20:55





















  • If you go to a command prompt and type SendEmail.py, what happens? Do you get the same error?

    – Bryan Oakley
    Nov 10 '14 at 20:44











  • no it works fine.I executed the same python file separately and then it worked fine.I used python SendEmail.py and it worked.

    – Valla
    Nov 10 '14 at 20:53






  • 1





    Do you notice what you just wrote? You said "I used python SendEmail.py". That's not what I asked, and that's not what you're doing in the script. At a prompt, type literally SendMail.py not python SendMail.py. I suspect you'll get the same error. If it doesn't work from the command line, it's not going to work from os.system().

    – Bryan Oakley
    Nov 10 '14 at 20:55



















If you go to a command prompt and type SendEmail.py, what happens? Do you get the same error?

– Bryan Oakley
Nov 10 '14 at 20:44





If you go to a command prompt and type SendEmail.py, what happens? Do you get the same error?

– Bryan Oakley
Nov 10 '14 at 20:44













no it works fine.I executed the same python file separately and then it worked fine.I used python SendEmail.py and it worked.

– Valla
Nov 10 '14 at 20:53





no it works fine.I executed the same python file separately and then it worked fine.I used python SendEmail.py and it worked.

– Valla
Nov 10 '14 at 20:53




1




1





Do you notice what you just wrote? You said "I used python SendEmail.py". That's not what I asked, and that's not what you're doing in the script. At a prompt, type literally SendMail.py not python SendMail.py. I suspect you'll get the same error. If it doesn't work from the command line, it's not going to work from os.system().

– Bryan Oakley
Nov 10 '14 at 20:55







Do you notice what you just wrote? You said "I used python SendEmail.py". That's not what I asked, and that's not what you're doing in the script. At a prompt, type literally SendMail.py not python SendMail.py. I suspect you'll get the same error. If it doesn't work from the command line, it's not going to work from os.system().

– Bryan Oakley
Nov 10 '14 at 20:55














4 Answers
4






active

oldest

votes


















7














I was able to figure out a way to call another python script on button click:



instead of using os.system('SendEmail.py') we need to use os.system('python SendEmail.py')






share|improve this answer































    2














    If your SendEmail.py is in the same location, use os.system('SendEmail.py'). If it's in a different location, use os.system('python SendEmail.py').






    share|improve this answer

































      0














      import sys
      import os
      from tkinter import *

      window=Tk()

      window.title("Running Python Script")
      window.geometry('550x200')

      def run():
      os.system('opencv_video.py')

      btn = Button(window, text="Click Me", bg="black", fg="white",command=run)
      btn.grid(column=0, row=0)

      window.mainloop()





      share|improve this answer































        -1














        #!/usr/bin/python
        import sys
        import os
        import tkinter as tk

        root = tk.Tk()

        def helloCallBack():
        os.system('call.py')
        #Keep_both_files_in_the_same_Folder
        b1=tk.Button(root, text="Calendar",bg="white",command=helloCallBack)
        b1.pack()
        root.mainloop()





        share|improve this answer


























        • Don't forget to actually answer the question. See stackoverflow.com/help/how-to-answer for some guidelines. The original question was asking for the cause of an error.

          – Brian Minton
          Oct 1 '18 at 17:25











        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f26852465%2fcalling-a-python-script-on-button-click-using-python-and-tkinter%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        7














        I was able to figure out a way to call another python script on button click:



        instead of using os.system('SendEmail.py') we need to use os.system('python SendEmail.py')






        share|improve this answer




























          7














          I was able to figure out a way to call another python script on button click:



          instead of using os.system('SendEmail.py') we need to use os.system('python SendEmail.py')






          share|improve this answer


























            7












            7








            7







            I was able to figure out a way to call another python script on button click:



            instead of using os.system('SendEmail.py') we need to use os.system('python SendEmail.py')






            share|improve this answer













            I was able to figure out a way to call another python script on button click:



            instead of using os.system('SendEmail.py') we need to use os.system('python SendEmail.py')







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 10 '14 at 21:11









            VallaValla

            93242752




            93242752

























                2














                If your SendEmail.py is in the same location, use os.system('SendEmail.py'). If it's in a different location, use os.system('python SendEmail.py').






                share|improve this answer






























                  2














                  If your SendEmail.py is in the same location, use os.system('SendEmail.py'). If it's in a different location, use os.system('python SendEmail.py').






                  share|improve this answer




























                    2












                    2








                    2







                    If your SendEmail.py is in the same location, use os.system('SendEmail.py'). If it's in a different location, use os.system('python SendEmail.py').






                    share|improve this answer















                    If your SendEmail.py is in the same location, use os.system('SendEmail.py'). If it's in a different location, use os.system('python SendEmail.py').







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Dec 28 '16 at 12:16









                    Fabian Schultz

                    8,16822540




                    8,16822540










                    answered Dec 28 '16 at 11:11









                    Zzmilanzz ZzmadubashazzZzmilanzz Zzmadubashazz

                    31733




                    31733























                        0














                        import sys
                        import os
                        from tkinter import *

                        window=Tk()

                        window.title("Running Python Script")
                        window.geometry('550x200')

                        def run():
                        os.system('opencv_video.py')

                        btn = Button(window, text="Click Me", bg="black", fg="white",command=run)
                        btn.grid(column=0, row=0)

                        window.mainloop()





                        share|improve this answer




























                          0














                          import sys
                          import os
                          from tkinter import *

                          window=Tk()

                          window.title("Running Python Script")
                          window.geometry('550x200')

                          def run():
                          os.system('opencv_video.py')

                          btn = Button(window, text="Click Me", bg="black", fg="white",command=run)
                          btn.grid(column=0, row=0)

                          window.mainloop()





                          share|improve this answer


























                            0












                            0








                            0







                            import sys
                            import os
                            from tkinter import *

                            window=Tk()

                            window.title("Running Python Script")
                            window.geometry('550x200')

                            def run():
                            os.system('opencv_video.py')

                            btn = Button(window, text="Click Me", bg="black", fg="white",command=run)
                            btn.grid(column=0, row=0)

                            window.mainloop()





                            share|improve this answer













                            import sys
                            import os
                            from tkinter import *

                            window=Tk()

                            window.title("Running Python Script")
                            window.geometry('550x200')

                            def run():
                            os.system('opencv_video.py')

                            btn = Button(window, text="Click Me", bg="black", fg="white",command=run)
                            btn.grid(column=0, row=0)

                            window.mainloop()






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 22 '18 at 6:21









                            RaaRaa

                            1




                            1























                                -1














                                #!/usr/bin/python
                                import sys
                                import os
                                import tkinter as tk

                                root = tk.Tk()

                                def helloCallBack():
                                os.system('call.py')
                                #Keep_both_files_in_the_same_Folder
                                b1=tk.Button(root, text="Calendar",bg="white",command=helloCallBack)
                                b1.pack()
                                root.mainloop()





                                share|improve this answer


























                                • Don't forget to actually answer the question. See stackoverflow.com/help/how-to-answer for some guidelines. The original question was asking for the cause of an error.

                                  – Brian Minton
                                  Oct 1 '18 at 17:25
















                                -1














                                #!/usr/bin/python
                                import sys
                                import os
                                import tkinter as tk

                                root = tk.Tk()

                                def helloCallBack():
                                os.system('call.py')
                                #Keep_both_files_in_the_same_Folder
                                b1=tk.Button(root, text="Calendar",bg="white",command=helloCallBack)
                                b1.pack()
                                root.mainloop()





                                share|improve this answer


























                                • Don't forget to actually answer the question. See stackoverflow.com/help/how-to-answer for some guidelines. The original question was asking for the cause of an error.

                                  – Brian Minton
                                  Oct 1 '18 at 17:25














                                -1












                                -1








                                -1







                                #!/usr/bin/python
                                import sys
                                import os
                                import tkinter as tk

                                root = tk.Tk()

                                def helloCallBack():
                                os.system('call.py')
                                #Keep_both_files_in_the_same_Folder
                                b1=tk.Button(root, text="Calendar",bg="white",command=helloCallBack)
                                b1.pack()
                                root.mainloop()





                                share|improve this answer















                                #!/usr/bin/python
                                import sys
                                import os
                                import tkinter as tk

                                root = tk.Tk()

                                def helloCallBack():
                                os.system('call.py')
                                #Keep_both_files_in_the_same_Folder
                                b1=tk.Button(root, text="Calendar",bg="white",command=helloCallBack)
                                b1.pack()
                                root.mainloop()






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Oct 1 '18 at 20:21









                                Michael

                                1,81551633




                                1,81551633










                                answered Oct 1 '18 at 16:05









                                mohit malimohit mali

                                11




                                11













                                • Don't forget to actually answer the question. See stackoverflow.com/help/how-to-answer for some guidelines. The original question was asking for the cause of an error.

                                  – Brian Minton
                                  Oct 1 '18 at 17:25



















                                • Don't forget to actually answer the question. See stackoverflow.com/help/how-to-answer for some guidelines. The original question was asking for the cause of an error.

                                  – Brian Minton
                                  Oct 1 '18 at 17:25

















                                Don't forget to actually answer the question. See stackoverflow.com/help/how-to-answer for some guidelines. The original question was asking for the cause of an error.

                                – Brian Minton
                                Oct 1 '18 at 17:25





                                Don't forget to actually answer the question. See stackoverflow.com/help/how-to-answer for some guidelines. The original question was asking for the cause of an error.

                                – Brian Minton
                                Oct 1 '18 at 17:25


















                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f26852465%2fcalling-a-python-script-on-button-click-using-python-and-tkinter%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                MongoDB - Not Authorized To Execute Command

                                in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

                                Npm cannot find a required file even through it is in the searched directory