使用tkinter为Python中的代码添加开始和停止按钮
我想使用tkinter为我的代码添加开始和停止按钮 我只希望当我点击scheduler.start的开始按钮时,代码会运行 当我点击scheduler.shutdown代码的停止按钮时 这是一个Python2.7版本,但不用担心,我只需要了解这段代码的运行方式 这是我的密码:使用tkinter为Python中的代码添加开始和停止按钮,python,tkinter,Python,Tkinter,我想使用tkinter为我的代码添加开始和停止按钮 我只希望当我点击scheduler.start的开始按钮时,代码会运行 当我点击scheduler.shutdown代码的停止按钮时 这是一个Python2.7版本,但不用担心,我只需要了解这段代码的运行方式 这是我的密码: if __name__ == '__main__': logging.basicConfig(filename='read.log', level=logging.INFO) logging.getLo
if __name__ == '__main__':
logging.basicConfig(filename='read.log', level=logging.INFO)
logging.getLogger('apscheduler').setLevel(logging.DEBUG)
scheduler = BackgroundScheduler()
scheduler.add_job(calstk, 'interval', seconds=20)
# scheduler.add_job(calmrp, 'interval', seconds=10)
# scheduler.add_job(caldisc, 'interval', seconds=15)
# leave space only for understanding for which I need to add **start Button**
scheduler.start() # for this scheduler.start()
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
try:
# stock = calstk()
#print stock
print '************************************************************************************'
# This is here to simulate application activity (which keeps the main thread alive).
while True:
time.sleep(10)
except (KeyboardInterrupt, SystemExit):
# Not strictly necessary if daemonic mode is enabled but should be done if possible
pass
# leave space only for understanding for which I need to add **Stop Button**
scheduler.shutdown()
# for this scheduler.shutdown()
我想为scheduler.start添加一个开始按钮
和scheduler.shutdown的停止按钮。
我真的需要这个代码,我几乎建立我的项目,我只需要这两个按钮来处理我的项目
import tkinter as tk
win = tk.Tk()
top = tk.Frame(win, padx = 20, pady = 20)
b1 = tk.Button(top, text='Start', padx = 10, pady = 10, command=scheduler.start)
b2 = tk.Button(top, text='Stop', padx = 10, pady = 10, command=scheduler.shutdown)
b1.pack(side=tk.LEFT)
b2.pack(side=tk.RIGHT)
top.pack()
win.mainloop()
这就是添加按钮的方法。兄弟,我不知道Tkinter的情况,如果你给我一个解决方案,它对我有好处。谢谢如果你的问题得到了回答,请标出答案。以便其他人知道查询已解决