鱼C论坛

 找回密码
 立即注册
查看: 1324|回复: 1

[已解决]求解,为什么这段自动按空格的代码会未响应

[复制链接]
发表于 2017-9-26 17:52:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. import win32api
  2. from tkinter import *
  3. from PIL import Image, ImageTk
  4. import time
  5. import win32con

  6. def fishingon():                 
  7.     i =1                        
  8.     while True:
  9.         win32api.keybd_event(32,0,0,0)
  10.         win32api.keybd_event(32,0,win32con.KEYEVENTF_KEYUP,0)
  11.         time.sleep(5)
  12.         if i ==2:
  13.             break


  14. def fishingstop():
  15.     i = 2
  16.    

  17. root = Tk()

  18. Button_fish = Button(root,text="开始钓鱼(釣り始まる)",font=("华文楷体",15),command=fishingon)
  19. Button_fish.pack()

  20. Button_stop = Button(root,text="停止钓鱼(釣り終わる)",font=("华文楷体",15),command=fishingstop)
  21. Button_stop.pack()
  22. mainloop()
复制代码
最佳答案
2017-9-26 19:34:07
用线程
  1. import win32api
  2. from tkinter import *
  3. import threading
  4. import time
  5. import win32con


  6. i =1
  7. def fishingon():
  8.     global i
  9.     i = 1
  10.     while True:
  11.         win32api.keybd_event(32,0,0,0)
  12.         win32api.keybd_event(32,0,win32con.KEYEVENTF_KEYUP,0)
  13.         print("ok!!!!!!!!!")
  14.         time.sleep(5)
  15.         if i ==2:
  16.             break

  17. def fishingstop():
  18.     global i
  19.     i = 2

  20. def MyThread(func, *args):
  21.     # 创建
  22.     t = threading.Thread(target=func, args=args)
  23.     # 守护
  24.     t.setDaemon(True)
  25.     # 守护 !!!
  26.     t.start()
  27.    

  28. root = Tk()

  29. Button_fish = Button(root,text="开始钓鱼(釣り始まる)",font=("华文楷体",15),command=lambda:MyThread(fishingon))
  30. Button_fish.pack()

  31. Button_stop = Button(root,text="停止钓鱼(釣り終わる)",font=("华文楷体",15),command=fishingstop)
  32. Button_stop.pack()
  33. mainloop()
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-9-26 19:34:07 | 显示全部楼层    本楼为最佳答案   
用线程
  1. import win32api
  2. from tkinter import *
  3. import threading
  4. import time
  5. import win32con


  6. i =1
  7. def fishingon():
  8.     global i
  9.     i = 1
  10.     while True:
  11.         win32api.keybd_event(32,0,0,0)
  12.         win32api.keybd_event(32,0,win32con.KEYEVENTF_KEYUP,0)
  13.         print("ok!!!!!!!!!")
  14.         time.sleep(5)
  15.         if i ==2:
  16.             break

  17. def fishingstop():
  18.     global i
  19.     i = 2

  20. def MyThread(func, *args):
  21.     # 创建
  22.     t = threading.Thread(target=func, args=args)
  23.     # 守护
  24.     t.setDaemon(True)
  25.     # 守护 !!!
  26.     t.start()
  27.    

  28. root = Tk()

  29. Button_fish = Button(root,text="开始钓鱼(釣り始まる)",font=("华文楷体",15),command=lambda:MyThread(fishingon))
  30. Button_fish.pack()

  31. Button_stop = Button(root,text="停止钓鱼(釣り終わる)",font=("华文楷体",15),command=fishingstop)
  32. Button_stop.pack()
  33. mainloop()
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-6 23:58

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表