使用 python 和 tkinter 在按钮单击时调用 python 脚本 [英] calling a python script on button click using python and tkinter

查看:215
本文介绍了使用 python 和 tkinter 在按钮单击时调用 python 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 python 脚本,它具有向用户发送电子邮件的功能.我执行了这个脚本,它工作正常.在另一个 python 脚本中,我只有一个按钮,所以当我点击这个按钮时,我希望另一个发送电子邮件的 python 脚本被执行.我编写了以下代码:

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:未找到.

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 脚本的方法:

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

我们需要使用 os.system('python SendEmail.py') 而不是使用 os.system('SendEmail.py')

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

这篇关于使用 python 和 tkinter 在按钮单击时调用 python 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆