how to trigger a function via another function

Asked

Viewed 47 times

0

i am making an app with Tkinter and need to trigger a function using another:

import pynput
import datetime
import tkinter
from tkinter import *
import pyautogui
import time
from pynput.keyboard import Key, Controller
win = Tk()
win.title('autoclass.enter V1')
win.geometry('500x500')

coord1= Entry(win, width=30)
coord1.place(x=178, y=120)
coord2= Entry(win, width=30)
coord2.place(x=178, y=155)
tempo= Entry(win, width=30)
tempo.place(x=178, y=207)
chat1= Entry(win, width=30)
chat1.place(x=178, y=254)
chat2= Entry(win, width=30)
chat2.place(x=178, y=280)
agora= Entry(win, width=30)
agora.place(x=178, y=320)



 def chronus():
    agora = hora.get()
    now = (datetime.datetime.now())
    if agora == now:
    
    else:

def start():
    time.sleep(2)
    b = coord2.get()
    c = coord1.get()
    d = int(c,0)
    e = int(b,0)

    f = tempo.get()
    g = int(f,0)
    h = (g * 60)

    i = chat1.get()
    j = chat2.get()
    k = int(i,0)
    l = int(j,0)


    pyautogui.click(d, e)
    time.sleep(g)
    pyautogui.moveTo(k, l, duration = 1) 
    pyautogui.click(k, l) 
    keyboard = Controller()
    time.sleep(2)
    time.sleep(8)
    keyboard.type(name.get())
    keyboard.press(Key.enter)
    keyboard.release(Key.enter)
[...]

the function chronus() need to trigger the start() when the time indicated is the same as the time the clock is, but how to make one trigger the other?

  • 2

    Within the if of function chronus() you perform the function call start(). To make this call just type start().

1 answer

2

def start():
    print("oi")

def chronus():
    agora = hora.get()
    now = (datetime.datetime.now())
    if agora == now:
        start()
    else:

It usually works that way.

  • Now ta giving error in function start: Indentationerror: expected an indented block

  • is using some text editor? for example sublime text, it has a way to convert "tabs" in 4 spaces. by default python uses 4 spaces to delimit code blocks, and it is not allowed to mix spaces with tabs (sometimes passes, sometimes the text editor automatically converts the tab to space). This is an identation error, just need to get the spacings correctly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.