User interface 从另一个tkinter脚本运行现有tkinter脚本

User interface 从另一个tkinter脚本运行现有tkinter脚本,user-interface,tkinter,python-3.4,User Interface,Tkinter,Python 3.4,我是python和tkinter的新手 我有一个工作的tkinter脚本(我希望避免编辑) 现在我正在编写一个脚本,它将成为顶级GUI。 这个脚本中的按钮应该启动带有一些命令行参数的现有脚本(比如从shell运行它,例如python3.4.1 script.py args) 我尝试了以下方法: 使用操作系统 btn2 = Button(frame2, text="Configure>>", command="os.system('python script.py args')")

我是python和tkinter的新手

我有一个工作的tkinter脚本(我希望避免编辑) 现在我正在编写一个脚本,它将成为顶级GUI。 这个脚本中的按钮应该启动带有一些命令行参数的现有脚本(比如从shell运行它,例如python3.4.1 script.py args)

我尝试了以下方法:

  • 使用操作系统

    btn2 = Button(frame2, text="Configure>>", command="os.system('python script.py args')")
    
  • 使用子流程

    def runSubProcess(self):
        p=subprocess.Popen(["python3.4.1","script.py args"],stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        output=p.communicate()[0]
    
  • 这两种方法都不起作用

    欢迎提出任何建议,谢谢

    编辑:我也不需要与新窗口通信,因为它将写入一个文件,稍后将使用该文件。只要控制从子窗口返回到父窗口就足够了(单击“确定”后)


    -Vinay

    您的第一种方法应该有效。但是,您将错误的内容传递给按钮的
    命令
    参数。应该向命令传递函数,而不是字符串。您可以使用lambda:

    btn2 = Button(frame2, text="Configure>>", command=lambda: os.system('python script.py args'))
    

    你的第一种方法应该有效。但是,您将错误的内容传递给按钮的
    命令
    参数。应该向命令传递函数,而不是字符串。您可以使用lambda:

    btn2 = Button(frame2, text="Configure>>", command=lambda: os.system('python script.py args'))
    

    嗨,它和lambda合作过。我还使用subprocess.call('pythonscript args',shell=true)使其工作。谢谢你的帮助。我很高兴它成功了。如果您认为此答案有帮助,您可以选择向上投票和/或接受此答案(单击左侧的复选符号)。您好,它与lambda一起工作。我还使用subprocess.call('pythonscript args',shell=true)使其工作。谢谢你的帮助。我很高兴它成功了。如果您认为此答案有帮助,您可以选择向上投票和/或接受此答案(单击左侧的复选符号)