我正在尝试使用tkinter从我的代码打开弹出gui窗口,该代码使用crontab在后台运行,但是它会出错。 当我从控制台运行此脚本时,它工作正常。 相关部分:
def copy():
global threshold
global primary
global secondary
root = Tk()
copy_popup = Toplevel(root)
copy_label = Label(copy_popup, text="Copying Files...")
copy_label.grid(column=0, row=0)
progress = ttk.Progressbar(copy_popup, orient="horizontal", length=200, mode="indeterminate")
progress.grid(column=1, row=0)
root.after(1, start_copy, progress, root)
root.mainloop()
def start_copy(progress, root):
copy_thread = threading.Thread(target=copy_files)
print("got here")
progress.start()
copy_thread.start()
copy_thread.join()
progress.stop()
root.destroy()
错误追溯:
Traceback (most recent call last):
File "/home/nimrco/PycharmProjects/Cron/cron.py", line 248, in <module>
main()
File "/home/nimrco/PycharmProjects/Cron/cron.py", line 230, in main
pending()
File "/home/nimrco/PycharmProjects/Cron/cron.py", line 81, in pending
copy()
File "/home/nimrco/PycharmProjects/Cron/cron.py", line 154, in copy
root = Tk()
File "/usr/lib/python3.5/tkinter/__init__.py", line 1880, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
任何人都有这方面的解决方案吗?提前谢谢你。