K
K
khaziev_m2018-02-25 21:05:53
Python
khaziev_m, 2018-02-25 21:05:53

How to stop a script from running on schedule in tkinter?

How to stop a scheduled task...

import schedule
...
def main():
    factories = get_factory()
    for factory in factories:
        parser_factory = ParserFactory(factory)
        parser_factory.update_db_with_parser()


def run_schedule():
    schedule.every(10).seconds.do(main)

    while True:
        schedule.run_pending()
        time.sleep(1)

...here:
from tkinter import *
import parser


def start():
    parser.seller_id = entry.get()
    parser.run_schedule()


def delete():
    entry.delete(0, END)

root = Tk()
# WxH+X+Y
root.geometry('320x240+720+360')
root.title('Parser GUI')

# поле ввода
entry = Entry(root)
entry.insert(0, 'Введите идентификатор')
entry.pack(side=TOP, expand=YES, fill=X)
# избавить от необходимости выполнять щелчок мышью
entry.focus()
# при нажатии клавиши Enter
entry.bind('<Return>', lambda event: start())
# при двойном щелчке левой кнопки мыши в поле ввода
entry.bind('<Double-1>', lambda event: delete())
# кнопка Start
start_btn = Button(root, text='Начать', command=start)
start_btn.pack(side=LEFT, expand=YES)
# кнопка Stop
stop_btn = Button(root, text='Остановить')
stop_btn.pack(side=RIGHT, expand=YES)

root.mainloop()

After clicking the "Start" button, the GUI window does not respond to input. You can only end the process in the terminal

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-02-25
@sanya84

Try threading or subprocess
You need to run the start() function on a thread.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question