如何制作时间。
我如何制作一个输入选项,其中输入的值用于睡眠,而不是代码“ Time.sleep(10)”中的时间,例如,i将30输入到PSG中。等待30秒,然后休息
import PySimpleGUI as Psg
import time
import pause
from pynput.keyboard import Key, Controller
loop = 0
cancel_loop = 0
punch_wait = 0
punch_time = 0
keyboard = Controller()
layout = [[Psg.Button("punch")],
[Psg.Button("Close")]]
window = Psg.Window("App", size=(300, 270)).Layout(layout)
def cancel():
if event == "Close":
pass
def d_press():
keyboard.press(Key.right)
pause.milliseconds(punch_time)
keyboard.release(Key.right)
pause.milliseconds(punch_wait)
keyboard.release(Key.space)
return event
def space_press():
keyboard.press(Key.space)
pause.milliseconds(1)
def movement():
d_press()
space_press()
while True:
event, values = window.read()
if event == Psg.WIN_CLOSED:
break
if event == "Close":
break
if event == "punch":
punch_wait = 300
punch_time = 85
loop = 1
while loop == 1:
movement()
cancel()
time.sleep(10)
break
How can I make an input option where the value inputted is used to sleep and not the time in the code 'time.sleep(10)', for example I inputted 30 into the Psg.Input after i press on punch i want it to wait 30 seconds then break
import PySimpleGUI as Psg
import time
import pause
from pynput.keyboard import Key, Controller
loop = 0
cancel_loop = 0
punch_wait = 0
punch_time = 0
keyboard = Controller()
layout = [[Psg.Button("punch")],
[Psg.Button("Close")]]
window = Psg.Window("App", size=(300, 270)).Layout(layout)
def cancel():
if event == "Close":
pass
def d_press():
keyboard.press(Key.right)
pause.milliseconds(punch_time)
keyboard.release(Key.right)
pause.milliseconds(punch_wait)
keyboard.release(Key.space)
return event
def space_press():
keyboard.press(Key.space)
pause.milliseconds(1)
def movement():
d_press()
space_press()
while True:
event, values = window.read()
if event == Psg.WIN_CLOSED:
break
if event == "Close":
break
if event == "punch":
punch_wait = 300
punch_time = 85
loop = 1
while loop == 1:
movement()
cancel()
time.sleep(10)
break
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调用
time.sleep
将在主线程中阻止您的代码,并且您的GUI可能没有响应。更喜欢在其他线程中进行。以下代码显示要走的路。
Call
time.sleep
will block your code in the main thread and there maybe no response for your GUI.Prefer to do it in other thread. Following code show the way to go.