I'm new to python, I'm building code for my project and I need that every time my iniciobot() function is repeated, it's counted and shown on my tkinter screen. I tried to do it using a global variable contagem, but nothing happens. How do I solve this? If anyone can help me I appreciate it.
here is the call
botao2 = Button(janela, text='Anunciar', image=foto2,
style='W.TButton', command=iniciobot)
botao2.pack(side=TOP)
contagem = 0
def iniciobot():
global contagem
contagem += 1
class InitBot1v: # a partir dessa classe pode começar a repetição
for InitBot1v in range(3):
driver.get('https://conta.olx.com.br/anuncios/publicados')
time.sleep(3)
driver.find_element_by_xpath('//*[@id="main-page-content"]/div[1]/div[1]/header/div[3]/div[2]/a').click()
try:
element = WebDriverWait(driver, 15).until(
ec.presence_of_element_located((By.XPATH, '//*[@id="input_subject"]'))
)
finally:
driver.find_element_by_xpath('//*[@id="input_subject"]').send_keys(random.choice(olxlist.lista_compras))
driver.find_element_by_xpath('//*[@id="input_body"]').send_keys(olxdescricao.lista_venda)
driver.find_element_by_xpath('//*[@id="category_item-1000"]').click()
driver.find_element_by_xpath('//*[@id="category_item-1100"]').click()
time.sleep(2)
driver.find_element_by_xpath(
'//*[@id="root"]/div[3]/form/div[1]/div/div[1]/div[3]/div[1]/div/div[1]/label/span').click()
driver.find_element_by_xpath('//*[@id="size"]').send_keys('1000')
driver.find_element_by_xpath('//*[@id="re_land_type"]').click()
driver.find_element_by_xpath('//*[@id="re_land_type"]/option[2]').click()
driver.find_element_by_xpath('//*[@id="price"]').send_keys('40000')
time.sleep(4)
pyautogui.click(1380, 447) # 1600x900 - x,y (1380, 447) click na tela da olx para fazer scroll
pyautogui.scroll(-2000)
time.sleep(2)
class pegar_pasta:
pyautogui.click(89,
879) # click no gerenciador de arquivos para ir na foto 1600x900 - x,y (89, 879)
time.sleep(0.2)
pyautogui.click(269,
801) # click na foto para fazer a seleção e os dois 'down' aqui dbaixo é pra n repetir as fotos 1600x900 - x,y (269, 801)
pyautogui.keyDown('down')
pyautogui.keyDown('down')
time.sleep(0.1)
pyautogui.keyDown('Shift') # segurar para selecionar as 3 fotos
time.sleep(0.5)
pyautogui.keyDown('down') # esses 2 'down' é pra selecionar as fotos
pyautogui.keyDown('down')
pyautogui.keyUp('Shift') # soltar o shift da seleção das fotos
time.sleep(1)
class enviar_foto:
pyautogui.mouseDown()
pyautogui.moveTo(212, 879) # 1600x900 - x,y (212, 879)
time.sleep(0.5)
pyautogui.moveTo(212, 870, 0.2) # 1600x900 - x,y (212, 870, 0.2)
time.sleep(0.2)
pyautogui.moveTo(190, 231, 1) # 1600x900 - x,y (190, 231, 1)
time.sleep(0.2)
pyautogui.mouseUp()
time.sleep(0.2)
driver.find_element_by_xpath('//*[@id="zipcode"]').send_keys(random.choice(olxcep.lista_cep))
time.sleep(0.3)
driver.find_element_by_xpath('//*[@id="ad_insertion_submit_button"]').click()
time.sleep(3)
driver.find_element_by_xpath('//*[@id="ad_insertion_submit_button"]').click()
time.sleep(10)
def mostrar_quantidade():
print(contagem)
janela = Tk()
janela.configure(border=40, background='white')
janela.title('Olx Bot Anúncio')
texto_espaco = Label(janela, text=contagem)
texto_espaco.pack(side=TOP)
janela.mainloop()