【发布时间】:2020-11-18 12:32:14
【问题描述】:
您好,我的问题是如何使命令 a 和 b 同时工作,我尝试了线程但线程立即执行命令,感谢您的帮助! 我是一名初学者程序员,所以对这个问题的任何帮助都会有很大帮助,这个项目旨在成为一个刷新机器人,但我无法弄清楚!
import tkinter as tk
from time import sleep
from selenium import webdriver
def a():
driver1 = webdriver.Chrome(executable_path="/Users/user/Downloads/chromedriver")#your file
driver1.get(entry.get())
while True:
sleep(5)
driver1.refresh()
def b():
app.destroy()
def c():
entry.delete(0, tk.END)
app = tk.Tk()
app.title("Youtube Bot")
app.geometry("425x350")
app.resizable(False, False)
app.configure(bg="#333436")
textOne = tk.Label(
text = "Youtube Bot",
font = ("Helvetica", 28),
fg = "white",
bg = "#333436",
height = "1"
)
textOne.grid(pady = 10)
entry = tk.Entry(
app,
width = 25,
font = ("Arial", 15),
fg = "white",
bg = "#6b6d75"
)
entry.focus_set()
entry.grid(padx=10, pady=18 )
entry.get()
entry.insert(0, "Paste Video Link")
buttonRefresh = tk.Button(
text = "Delete",
font = ("Arial", 15),
width = 8,
command = c
)
buttonRefresh.grid(padx = 6)
buttonOne = tk.Button(
text = "Start process",
font =("Helvetica", 20),
height = "3",
width = "20",
command = a
)
buttonOne.grid()
buttonTwo = tk.Button(
text="Stop process",
font=("Helvetica", 20),
height="3",
width="20",
command = b
)
buttonTwo.grid(pady=20)
textOne.grid(row = 0, column = 1)
entry.grid(row = 1, column = 1)
buttonRefresh.grid(row = 1, column = 0)
buttonOne.grid(row = 2, column = 1)
buttonTwo.grid(row = 3, column = 1)
app.mainloop()
【问题讨论】:
-
这很混乱,更多细节会有所帮助
-
@coderoftheday 这是所有代码,当您尝试运行它时,您需要插入视频的链接,当您按下第一个按钮时,链接会打开并每 5 秒刷新一次页面(这是tkinter 窗口冻结时的部分),我需要让它能够解冻并正常工作以处理多个请求
-
使用线程模块?
-
@coderoftheday 你能发个例子吗?
标签: python multithreading tkinter