Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tkinter auto press button
#1
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
Reply
#2
You can use after().

https://pythonguides.com/python-tkinter-after-method/
kucingkembar likes this post
Reply
#3
(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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to open a popup window in tkinter with entry,label and button lunacy90 1 902 Sep-01-2023, 12:07 AM
Last Post: lunacy90
  Tkinter button images not showing up lunacy90 7 1,620 Aug-31-2023, 06:39 PM
Last Post: deanhystad
Bug tkinter.TclError: bad window path name "!button" V1ber 2 806 Aug-14-2023, 02:46 PM
Last Post: V1ber
  How to break out of a for loop on button press? philipbergwerf 6 1,792 Oct-06-2022, 03:12 PM
Last Post: philipbergwerf
  Closing Threads and the chrome window it spawned from Tkinter close button law 0 1,717 Jan-08-2022, 12:13 PM
Last Post: law
  Auto increament in Entry field. in tkinter GUI cybertooth 7 4,145 Sep-17-2021, 07:56 AM
Last Post: cybertooth
  Problem using a button with tkinter SmukasPlays 6 3,318 Jul-02-2020, 08:06 PM
Last Post: SmukasPlays
  Use a button in Tkinter to run a Python function Pedroski55 4 3,283 Jun-28-2020, 05:02 AM
Last Post: ndc85430
  Function assigned at a button in tkinter riccardoob 9 4,200 Oct-06-2019, 11:14 AM
Last Post: riccardoob
  tkinter button executes button before being clicked SheeppOSU 1 3,801 Apr-01-2019, 10:51 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020