英文:
how to know if a function has been run in python 3.11
问题
以下是要翻译的代码部分:
我有一个带有tkinter(GUI)按钮的代码。当你按下按钮时,例如,我使用def块声明的press()函数会运行。我想知道如何检查函数是否已经运行,并在if块中使用它。
示例:
def press()
print("hello world")
press()
while True:
if press()已经运行:
print("已打印")
你能帮我吗?谢谢。
英文:
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.
答案1
得分: 4
这是一个非常基本的解决方案,使用了一个标志。
press_been_run = False
def press():
print("hello world")
global press_been_run
press_been_run = True
press()
if press_been_run:
print("printed")
英文:
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")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论