1

I have code that has a tkinter ( GUI ) button in it. when you press the button , for example , the press() function that I declared with a def block runs. i want to know how to check if a function has been run and use it in a if block. example:

def press()
    print("hello world")
press()

while True() :
    if press() has been runned (?) :
        print("printed")

can you help me with this? thanks.

Parsa Ad
  • 91
  • 6

1 Answers1

4

This is a very basic solution by using a flag

press_been_run = False

def press():
    print("hello world")
    global press_been_run 
    press_been_run = True

press()

if press_been_run:
    print("printed")
Thingamabobs
  • 7,274
  • 5
  • 21
  • 54
Mattravel
  • 1,358
  • 1
  • 15
  • wait. it's so basic , why i did not think of this? but maybe it will not answer in my code. let me try :) – Parsa Ad Feb 24 '23 at 08:59
  • 1
    While I do agree with the method you are using, the fact the OP wants to run this in the context of a GUI eventloop makes the `while True` loop quite dangerous. – Thingamabobs Feb 24 '23 at 09:00