Python Forum

Full Version: tkinter auto press button
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi, sorry for my bad english,
i have this case:

import tkinter

TheWindow = tkinter.Tk()

def AddOne():
    value = int(int(TextBox.get()) + 1)
    TextBox.delete(0, tkinter.END)
    TextBox.insert(0, str(value))
def RemOne():
    value = int(int(TextBox.get()) - 10)
    TextBox.delete(0, tkinter.END)
    TextBox.insert(0, str(value))
   

PlusButton  = tkinter.Button(TheWindow, text="Add 1", command = AddOne)
MinusButton = tkinter.Button(TheWindow, text="Remove 10", command = RemOne)

TextBox.insert(0, 0)

TextBox.pack()
PlusButton.pack()
MinusButton.pack()
TheWindow.mainloop()
as you can see the program is very simple,
and my question is, how make the "AddOne()" function or "Add 1" is called every 1 second?
I ask this because (as far I know) the python is procedural programming, and this task require Object Oriented one

thank you for reading, and have a nice day
(Dec-24-2021, 01:18 PM)deanhystad Wrote: [ -> ]You can use after().

https://pythonguides.com/python-tkinter-after-method/
thank you deanhystad, I will study it

EDIT:
Thank you again deanhystad for your information, now my code is worked as I intended
this is the script if others want to know

import tkinter

TheWindow = tkinter.Tk()

def AddOne():
    value = int(int(TextBox.get()) + 1)
    TextBox.delete(0, tkinter.END)
    TextBox.insert(0, str(value))
def RemOne():
    value = int(int(TextBox.get()) - 10)
    TextBox.delete(0, tkinter.END)
    TextBox.insert(0, str(value))
def TheLooping():
    AddOne()
    TheWindow.after(1000, TheLooping)

PlusButton  = tkinter.Button(TheWindow, text="Add 1",     command = AddOne)
MinusButton = tkinter.Button(TheWindow, text="Remove 10", command = RemOne)

TextBox = tkinter.Entry(TheWindow, text="0")
TextBox.insert(0, 0)
TextBox.pack()
PlusButton.pack()
MinusButton.pack()
TheWindow.after(1000, TheLooping)
TheWindow.mainloop()