[英]How to call a function in python at different times?
I need to call a certain function when the button is clicked and the code I wrote works perfectly only when the button is pressed the first time.单击按钮时,我需要调用某个 function 并且我编写的代码仅在第一次按下按钮时才能正常工作。 If I press the button again It won't call the function but it prints the string I coded to print when the button is pressed.What can I use to make the function able to call multiple times?如果我再次按下按钮它不会调用 function 但它会在按下按钮时打印我编码的字符串。我可以使用什么来使 function 能够多次调用? Thanks.谢谢。 Here is the code.这是代码。 Please Help Me请帮我
sg.theme('DarkAmber')
layout = [ [sg.Text('URL'), sg.InputText()],
[sg.Button('Ok'), sg.Button('Cancel')]]
window = sg.Window('Window Title', layout)
while True:
event, values = window.read()
if event in (None, 'Cancel'): # if user closes window or clicks cancel
break
url = values[0]
Mainfunction()
print('Button pressed here is the value ', values[0])
I actually made an simple error that would make the function work the correct way on the second time it is called.我实际上犯了一个简单的错误,它会使 function 在第二次被调用时以正确的方式工作。 So Myfunction is like所以 Myfunction 就像
var1 = 0
def Function:
if(var1 == 0):
//do some shit
var1 = var1 + 1
if(var1 == 1):
//do some shit
var1 = var1 + 1
So, I found out the Function is being called and executed but the arguments does not meet their requirements(Or some wierd shit. Am a NOOB) defining the variable inside the function made would do the work.所以,我发现 Function 正在被调用和执行,但是 arguments 不符合他们的要求(或者一些奇怪的狗屎。我是一个 NOOB)在 ZC1C425268E68385D1AB4ZZZC17A94F1 中定义变量会做的工作Likeways, The code would be,同样,代码将是,
def Function:
global var1 // If you wanna make it global
var1 = 0
if(var1 == 0):
//do some shit
var1 = var1 + 1
if(var1 == 1):
//do some shit
var1 = var1 + 1
``` Hope it Helped You
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.