TamP
Posts: 72
Joined: Mon Feb 19, 2018 1:28 pm

Pyw script using tkinter

Fri Apr 20, 2018 2:04 pm

I am trying to get a python 3.5 script to run when the pi3B+ boots
The script runs OK when I run it from Idle but all the methods I have tried, do not start the script at boot time
A beginner would appreciate some help

scotty101
Posts: 2795
Joined: Fri Jun 08, 2012 6:03 pm

Re: Pyw script using tkinter

Fri Apr 20, 2018 2:06 pm

Perhaps you should share your code and what methods you've tried so we aren't guessing.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

TamP
Posts: 72
Joined: Mon Feb 19, 2018 1:28 pm

Re: Pyw script using tkinter

Fri Apr 20, 2018 2:39 pm

The script is in /home/pi
I edited autostart...
Typed into a terminal..
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

and added the following line to the bottom...
@sudo /usr/bin/python /home/pi/Test.py
saved it
typed sudo chmod +x Test.py
rebooted, but the script doesnt run


This is the little example I was trying to run at boot
Its called Test.py

from tkinter import Tk, Label, Button
class MyFirstGUI:
def __init__(self, master):
self.master = master
master.title("A simple GUI")
master.geometry("500x500")
self.label = Label(master, text="This is my first GUI!")
self.label.pack()

self.greet_button = Button(master, text="Greet", command=self.greet)
self.greet_button.pack()

self.close_button = Button(master, text="Close", command=master.quit)
self.close_button.pack()

def greet(self):
print("Greetings!")

root = Tk()
my_gui = MyFirstGUI(root)
root.mainloop()

B.Goode
Posts: 5587
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Pyw script using tkinter

Fri Apr 20, 2018 2:43 pm

I am trying to get a python 3.5 script to run when the pi3B+ boots
But you are invoking it with /usr/bin/python, which will almost certainly run it with Python2. (And the incompatible names for the tkinter library across the 2 variants of python mean that it will certainly fail to run if started wrongly.)

TamP
Posts: 72
Joined: Mon Feb 19, 2018 1:28 pm

Re: Pyw script using tkinter

Fri Apr 20, 2018 2:59 pm

Python 3.5 is my default. If I type python into a terminal, python 3.5 starts
I will add a shebang #!/usr/bin/env python3 and see if that works

B.Goode
Posts: 5587
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Pyw script using tkinter

Fri Apr 20, 2018 3:06 pm

I don't know, and don't particularly care, but I wonder whether your default aliasing of /usr/bin/python to Python3 is effective while the root user is executing /etc/xdg/lxsession/LXDE-pi/autostart during system startup ?

But it seems to me that that sort of customisation would be worth mentioning in your initial query.

Good luck with solving your problem: I will not be contributing any further.

TamP
Posts: 72
Joined: Mon Feb 19, 2018 1:28 pm

Re: Pyw script using tkinter

Fri Apr 20, 2018 3:31 pm

Good (pun intended)

Return to “Python”

Who is online

Users browsing this forum: No registered users and 5 guests