首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >从另一个程序启动python程序

从另一个程序启动python程序
EN

Stack Overflow用户
提问于 2017-12-03 22:38:50
回答 3查看 79关注 0票数 1

我正在为我的计算机科学A级课程制作一个库存控制系统。我的问题是,在点击Button1之后,我不知道如何让python启动一个不同的python程序。

from tkinter import *
top=Tk()

Button1= Button(top,text='UPDATE STOCK', width=40)
Button1.place(x=80, y=20)

mainloop()
EN

回答 3

Stack Overflow用户

发布于 2017-12-03 22:49:19

from Tkinter import Tk, Button, mainloop
import subprocess

def ext_python_script(event):
    subprocess.call(["python2.7", "sss.py"])   

if __name__ == '__main__':
    top = Tk()

    Button1 = Button(top, text='UPDATE STOCK', width=20, height=10)
    Button1.place(x=10, y=20)
    Button1.bind("<Button-1>", ext_python_script)

mainloop()

我们可以在这里使用bind。

票数 0
EN

Stack Overflow用户

发布于 2017-12-03 22:54:42

import os
from tkinter import*
import subprocess

def otherlaunch():
    subprocess.call(['python.exe', "filename.py"]) # filename.py is the file

top=Tk()

top.title('Stock Control')
top.geometry('400x200')

Button1= Button(top,text='UPDATE STOCK', width=40,command=otherlaunch)
Button1.place(x=80, y=20)


mainloop()
票数 0
EN

Stack Overflow用户

发布于 2018-05-31 16:36:49

您可以使用import语句从一个python程序加载另一个程序,并使用command参数在单击按钮时执行某些操作,如下所示:

import os 
from tkinter import*
top=Tk()

top.title('Stock Control')
top.geometry('400x200')

def run_other():
    import filename  #notice that it is not a string, and there is no '.py'

Button1= Button(top,text='UPDATE STOCK', width=40, command=run_other)
Button1.place(x=80, y=20)


mainloop()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47619446

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档