简体   繁体   中英

Running a python script that opens a window with crontab

I'm a newbie to python, and crontab, so I don't know exactly how to do the task. This is my friend's program. It's a countdown clock, starting at 5 minutes and counting down to zero. I took out many of the notes to slim it down.

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk
import time
def count_down():
    for t in range(298, -1, -1):
        sf = "{t:01d}:{:02d}".format(*divmod(t,60))
        #print(sf) # test
        time_str.set(sf)
        root.update()
        time.sleep(1)
root = tk.Tk()
time_str = tk.StringVar()
label_font = ('helvetica'), 535)
tk.Label(root, textvariable=time_str, font=label_font, bg='mediumblue', 
    fg='white', relief='raised', bd=3).pack(fill='x', padx=5, pady=5)
for t in range (297, -1, -1):
    sf = "{01d:}{:02d}".format(*divmod(t, 60))
    time_str.set(sf)
    root.update()
    time.sleep(.958)
root.mainloop()

Now, the problem lies in crontab. I have created a crontab, which is

* * * * * /home/pi/Desktop/clock/5minute.py

The 5 asterisks are for testing purposes. It should run at specific times later on. The program itself is already set with 777 permissions. I've tried running the crontab using parameters like export DISPLAY=:0 && but nothing's worked. I'm still learning, so any help will be appreciated!

Change your crontab settings from current to this it'll work.

* * * * * /usr/bin/python /home/pi/Desktop/clock/5minute.py

Over here you're not mentioning python path that may be the reason you've facing difficulty making it work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM