简体   繁体   English

tkinter按钮无法打开不同的Python代码

[英]tkinter button unable to open different python code

I am trying to run a .py file from another python code using the following sequence. 我正在尝试使用以下顺序从另一个python代码运行.py文件。

from tkinter import *
import os
import sys

def open_SS():
    print('processing')
    os.system('cd /home/pi/Desktop/Backup')
    os.system('python p.py')

def close_window(): 
    master.destroy()

master = Tk()

master.minsize(width=500, height=300)

Button(master, text='Exit', command=close_window).grid(row=12, column=6, sticky=W, pady=4)
Button(master, text='SS', command=open_SS).grid(row=12, column=8, sticky=W, pady=4)

mainloop( )

The Exit button does the command, but the 'SS' button does not, the word 'processing' does get printed, just the running of the p.py file. “退出”按钮执行命令,但是“ SS”按钮不执行,仅显示p.py文件的运行,“处理”一词被打印出来。 I tried running those two os.system commands on a command terminal and it works fine. 我试着在命令终端上运行这两个os.system命令,它工作正常。 p.py is supposed to input GPIO signals to a Raspberry Pi. p.py应该将GPIO信号输入到Raspberry Pi。

from tkinter import *

import os

import sys

master = Tk()

def open_SS():

    print('processing')
    os.system("python /home/pi/Desktop/Backup/p.py")

btn=Button(master,text="click here")

btn.grid(row=0,column=1)

btn.bind("<Button>",open_SS)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM