0
I have this program which is a kind of 'Force Brute' (I automated a process of clicking on a place, typing a number, and clicking elsewhere with @Pyautogui), I need to use a loop but when the loop starts Tkinter to, so I couldn’t think of how to do something to pause the loop! the code:
from tkinter import *
import pyautogui
import time
class ForceBrute:
def __init__(self,master=None):
#faz com que a janela não possa ser redimensionada pelo usuario
master.resizable(width=False,height=False)
#Containers para os itens da interface
self.con1 = Frame(master)
self.con1['pady'] = 8
self.con1.pack()
self.con2 = Frame(master)
self.con2['pady'] = 15
self.con2.pack()
self.con3 = Frame(master)
self.con3['pady'] = 30
self.con3.pack()
self.con4 = Frame(master)
self.con4['pady'] = 10
self.con4.pack()
#itens da interface
self.tTitle = Label(self.con1)
self.tTitle['font'] = ('Roboto','30')
self.tTitle['text'] = 'SiriusForce'
self.tTitle.pack()
#recebe o valor de aparti de quando deve iniciar
self.eDe = Entry(self.con2,justify = 'center',relief=RIDGE,width=3)
self.eDe['font'] = ('Roboto', '20')
self.eDe.pack(side=LEFT)
#coloca 100 no campo como padrão
self.eDe.insert(0,'100')
self.tAte = Label(self.con2)
self.tAte['font'] = ('Roboto', '20')
self.tAte['text'] = 'Ate:'
self.tAte.pack(side=LEFT)
#recebe ate que valor deve ir
self.eAte = Entry(self.con2,justify = 'center',relief=RIDGE,width=3)
self.eAte['font'] = ('Roboto', '20')
self.eAte.pack(side=LEFT)
self.eAte.insert(0,'999')
#botão para iniciar
self.bIniciar = Button(self.con3,relief=RIDGE,fg='blue')
self.bIniciar['font'] =('Roboto', '25')
self.bIniciar['text'] = 'Iniciar'
self.bIniciar['command'] = self.iniciar
self.bIniciar.pack(side=LEFT)
self.bPausar = Button(self.con3,relief=RIDGE,fg='red')
self.bPausar['font'] =('Roboto', '25')
self.bPausar['text'] = 'Pausar'
# self.bPausar['command'] = seria para pausar o 'laço'
self.bPausar.pack(side=LEFT)
#exibe em que numero parou
self.eCont = Entry(self.con4,justify= 'center',relief=RIDGE,width=3,bg='black',fg='green')
self.eCont['font'] = ('Roboto', '30')
self.eCont.pack()
self.cod = 0
def iniciar(self):
self.de = int(self.eDe.get()) -1
self.ate = int(self.eAte.get())
print('Iniciado De:',self.de,'Ate:',self.ate) # só para visualizar
self.cod = self.de
while(self.cod < self.ate):
self.cod +=1
pyautogui.doubleClick(697,363)
pyautogui.typewrite(str(self.cod))
print(self.cod)
self.eCont.delete(0,END)
self.eCont.insert(0,self.cod)
pyautogui.click(880,516)
time.sleep(1.5)
root = Tk()
root.geometry('220x350+400+100')
root.title('Generico')
root.attributes('-topmost',True)
ForceBrute(root)
root.mainloop()
I’ve seen in some places I can use 'root.after()' but I couldn’t implement.
I had an initial oddity for using directly
self.after
. So I went to see that in my play projects I always inherit fromtk.Frame
, then that inheritance would be part of the fieldself.master
of your solution. Very good the answer– Jefferson Quesado
That - in particular, I consider nay inherit from Tk. Frame a major breakthrough - I don’t know why the tutorials keep recommending this: it’s a well-known anti-pattern (its class gets hundreds of attributes and methods that have no relation to the logic of its application. Keeping a reference to root in any attribute (in the self.master case) solves this.
– jsbueno
Once again Jsbueno saving the day kkkk! solved my problem, thank you! : 3
– Junior Lima