0

When user press start it starts selenium goes to tinder logins and starts swiping, added another button to stop program but cant get my head around it to make it work code.py have function quit() that is driver.quit() but how to place that. I'm new to python and programming.Thanks

import threading
from tkinter import *
import code
import time


def liker():
    new_canvas.itemconfig(loading, text="Loading..Please wait")
    start = code.TinderBot()
    time.sleep(30)
    start.log()
    time.sleep(10)
    new_canvas.itemconfig(loading, text="Starting to swipe...")
    start.swipe()


def new_process():
    threading.Thread(target=liker).start()
    

def close_window():
    pass

def update_counter():
    new_canvas.itemconfig(likes_counter, text=code.count)
    window.after(1000, update_counter)


window = Tk()
window.minsize(width=640, height=359)
window.title("Tinder Bot")


img = PhotoImage(file="love.png")

new_canvas = Canvas(window, width=640, height=359)
new_canvas.pack(fill="both", expand=True)

new_canvas.create_image(0, 0, image=img, anchor="nw")
welcome = new_canvas.create_text(320, 50, text="Welcome to Tinder Bot", font=("Halvetica", 30))
loading = new_canvas.create_text(320, 150, text="Press Start", font=("Halvetica", 20))
likes = new_canvas.create_text(190, 200, text="Likes counter:", font=("Halvetica", 20))
likes_counter = new_canvas.create_text(310, 200, text="0", font=("Halvetica", 20))

start_button = Button(text="Start Program", command=new_process)
stop_button = Button(text="Stop Program", command=close_window)


button1 = new_canvas.create_window(320, 300, window=start_button)
button2 = new_canvas.create_window(320, 330, window=stop_button)

update_counter()

window.mainloop()
Matiiss
  • 5,970
  • 2
  • 12
  • 29
  • 1
    Please provide a [mre] You make us guess. – Thingamabobs Nov 03 '21 at 08:32
  • don't call `tkinter` stuff from other threads – Matiiss Nov 03 '21 at 09:39
  • There is no function provided by python threading module to stop a running thread. If you just want to terminate the thread when the main window is closed, you can set the `daemon` option to `True` when creating the thread object. Then you can call `window.destroy()` inside `close_window()`. – acw1668 Nov 03 '21 at 10:26
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Adam Jaamour Nov 03 '21 at 11:29
  • Sorry if wasn't very clear.Currently when user press "start program" it will open webdriver chrome goes to tinder log ins and starts swiping(using selenium).As you can see there is another button "stop program" button so my problem is how to make that when "stop program" button pressed it would close browser that was opened when user pressed "start button". – SilverSky Nov 03 '21 at 17:30
  • use subprocesses. Find a solution [here](https://stackoverflow.com/a/65607405) – Nde Kong Sep 05 '22 at 22:53

0 Answers0