I am working on this project where I have Raspberry Pi 3 with full Raspbian (with GUI) connected to a 7" screen. I created a Python 3 script:
// gui.py import tkinter as tk root = tk.Tk() root.title("My Dash") root.mainloop()
I then created a shell script to run this file:
// test.sh python3 gui.py
Finally I created a PHP file to run this shell script:
// run.php <?php shell_exec("sudo /bin/bash test.sh"); ?>
All these files reside in
www-data set as both the user and user-group. However, when you run the PHP file nothing happens.
I've tried redirecting errors to a log file and it gives me the following error:
(tkinter.TclError: couldn't connect to display ":0.0")
If I run the Python file directly in the terminal, it displays the GUI successfully.
Can TKinter scripts only be run from the terminal and not from a webpage? If so, is there some kind of workaround? I'm trying to develop a web application where you can fire off TKinter windows from buttons on the site.