C Vith
C Vith

Reputation: 111

tkinter button unable to open different python code

I am trying to run a .py file from another python code using the following sequence.

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. I tried running those two os.system commands on a command terminal and it works fine. p.py is supposed to input GPIO signals to a Raspberry Pi.

Upvotes: 1

Views: 67

Answers (1)

Devdatt
Devdatt

Reputation: 82

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)

Upvotes: 2

Related Questions