Mohd Nabeel
Mohd Nabeel

Reputation: 13

What should I do on the button to run my python script

Here is the code which is working fine. The problem is I have made a virtual environment to run my python file. So, I have made a button, so when onClick I am calling the main.py file(There are other python files imported in this file) the problem is when I am clicking on the Click Me! button then it is opening my python script in Pycharm. What should I do?

from tkinter import *
import os
import sys

window=Tk()

window.title("Vehicular Monitoring System")
window.geometry('550x200')

def run():
    os.system('helmet.py')


B = Button(window, text ="Click Me!",command=run)

B.pack()
window.mainloop()

After clicking the button the module should execute instead of opening in Pycharm.

Upvotes: 0

Views: 210

Answers (1)

Alec
Alec

Reputation: 9536

os.system("command") passes the command, with any arguments, to your system's shell. So

os.system("python helmet.py -any args")  # you don't need any arguments

will work

Upvotes: 1

Related Questions