adipandas/python-gui-demos

Run a python script and get results on button click

shijithkappoor opened this issue · 3 comments

I want to take state of radiobuttons as parameter and run a python script on a button click. This should also return me an integer value which i want to display. Existing tutorials are limited to button click and text display. Could you help me with this?

It should be easy. As you want to display a value on button click, use the button click callback and save that value as the member variable in your app class. And as the value of the member variable gets updated on button click, you can use the update for display.
You can refer the following code in the repo:
https://github.com/adipandas/python-gui-demos/blob/master/src/program4.py

What i really need is to run a .py file in my local system. When i click the button, it should run the python file within the system. Is that possible or do i have to copy the script to the gui code and and combine all to an exe file?

To run a python script from you python code, there are more than few ways.

  1. You can treat your python script file like a module where you can just do import file. Note that if your file is called file.py, your import should not include the .py extension at the end.
  2. You can also use exec command: execfile('file.py').
  3. You can use os module (import os) to execute the file: os.system('python file.py').

You can use any of these methods to execute another file in your python code. You will have to add these few lines in your callback function for the radio button.