Hello.
I'm a beginner who is studying Python.
I'm just making a program that takes a simple screen shot using Python Tkinter.
I'm asking the seniors like this because there's a stop phenomenon with the following contents.
The sequence of program actions is as follows.
Window -> Click Start Button -> Watch mouse wheel buttons -> Take screenshot when clicking mouse wheel buttons -> Stopping
(The way I want to implement it is simply to press the Start button and then continue to take screenshots whenever the mouse wheel button is pressed.)
Below is the source code.
import pyautogui
import time
import mouse
import threading
from tkinter import *
# Creating a window window and adjusting the button screen
root = Tk()
root.title ("Taking Wheel Button SC")
root.geometry("540x480+100+100")
root.resizable(False,FALSE)
# Press Start button to monitor mouse wheel button ->Take a screenshot when clicking the wheel button
def btnscreen():
while True:
if mouse.is_pressed("middle"):
pyautogui.hotkey('win','prtscr')
if pyautogui.press('z'):
break
# Create Start Button
btn6 = Button (root,text='start button', command=btnscreen)
btn6.pack()
# Keep windows open
root.mainloop()
(After googling, it says to implement threads and timers, but I don't know how to apply them to the current code.)
That's it. Sunbae, please answer. Thank you.
python tkinter gui
You can use the threading module.
import threading
def th():
th = threading.Thread(target=btnscreen)
th.daemon = True
th.start()
def btnscreen():
while True:
if mouse.is_pressed("middle"):
pyautogui.hotkey('win','prtscr')
if pyautogui.press('z'):
break
btn6 = Button (root,text='start button',command=th)
btn6.pack()
I don't know much about tkinter. I'm not good enough. I'm not good enough with questions. I'm leaving a message just in case.
Does it mean that the program stops? Does it mean that the computer is going to stop?
I'm afraid the computer will stop, so I can't run the code.
From the code, it seems that btnscreen() works when you click the mouse wheel. I think there's a problem with that part.
def btnscreen():
while True:
if mouse.is_pressed("middle"):
pyautogui.hotkey('win','prtscr')
if pyautogui.press('z'):
break
"""
Break does not work unless the z key is pressed, so it looks like an infinite loop.
In other words, if there is no additional manipulation,
while True:
pass
Because it is in the same state as , the cpu load is expected during the operation.
"""
I think it should be modified as follows.
def btnscreen():
if mouse.is_pressed("middle"):
pyautogui.hotkey('win','prtscr')
912 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
581 PHP ssh2_scp_send fails to send files as intended
610 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.