简体   繁体   English

运行一个使用crontab打开窗口的python脚本

[英]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. 我是python和crontab的新手,所以我不知道该怎么做。 This is my friend's program. 这是我朋友的程序。 It's a countdown clock, starting at 5 minutes and counting down to zero. 这是一个倒数时钟,从5分钟开始,倒数到零。 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. 现在,问题出在crontab。 I have created a crontab, which is 我创建了一个crontab,

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

The 5 asterisks are for testing purposes. 5个星号用于测试目的。 It should run at specific times later on. 它应在以后的特定时间运行。 The program itself is already set with 777 permissions. 该程序本身已经设置了777权限。 I've tried running the crontab using parameters like export DISPLAY=:0 && but nothing's worked. 我尝试使用诸如export DISPLAY=:0 &&类的参数运行crontab,但是没有任何效果。 I'm still learning, so any help will be appreciated! 我仍在学习,所以我们将不胜感激!

Change your crontab settings from current to this it'll work. 将您的crontab设置从当前更改为此设置即可。

* * * * * /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. 在这里,您没有提到python路径,这可能是您难以使其正常工作的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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