・ I use temas in my company. If you do not operate the PC for 15 minutes or more, the status will be left. That's a problem. ・ Sometimes I want to take a break. ・ I was able to operate the mouse on the screen for the time being, but there may be various bugs. ・ Because I am a beginner in programming, various things do not go well. Great person to help.
By the way, even if I moved the mouse with the script, the status of teams was absent. Remorse ...
After pressing the start button,
working.py
import tkinter as tk
import pyautogui as pgui
import random
import datetime
import time
import subprocess
import string
import requests
class Application(tk.Frame):
def __init__(self, master):
super().__init__(master)
master.geometry("230x130")
master.title("Working!")
self.create_widgets()
def create_widgets(self):
self.grid(column=0, row=0, sticky=tk.NSEW, padx=5, pady=5)
self.time_label = tk.Label(self, text="Time designation(Minutes)").grid(column=0, row=0, pady=10)
self.time_box = tk.Entry(self)
self.time_box.insert(0, '60')
self.time_box.grid(column=1, row=0, sticky=tk.EW, padx=3)
self.work_label = tk.Label(self, text="Today's work").grid(column=0, row=1, pady=10)
self.status = tk.Label(self, text="Get serious from now on")
self.status.grid(column=1, row=1, sticky=tk.EW, padx=3)
self.start_btn = tk.Button(self, text="start", command=self.we_love_work).grid(column=1, row=2)
#Button action
def we_love_work(self):
#action_flg = random.randint(1, 3)
action_flg = 1
self.status.config(text="Mouse messing around") #Will not update
time_box_value = self.time_box.get()
end_time = datetime.datetime.now() + datetime.timedelta(minutes=int(time_box_value))
while True:
if datetime.datetime.now() >= end_time:
break
if action_flg == 1:
self.do_mouse()
elif action_flg == 2:
self.do_keyboard()
elif action_flg == 3:
self.do_news()
def do_mouse(self):
window_x = 1366
window_y = 768
for i in range(50):
point_x = random.randrange(0, window_x)
point_y = random.randrange(0, window_y)
pgui.moveTo(point_x, point_y, duration=1)
time.sleep(3)
def do_keyboard(self):
#I can operate the keyboard, but I can't write well in the memo
process = subprocess.Popen(r'C:\Windows\System32\notepad.exe')
pgui.click(50, 50)
for i in range(10):
pgui.typewrite(self.random_string(100))
pgui.typewrite('\r\n')
time.sleep(3)
process.kill()
def do_news(self):
keyword = "latest"
url = 'https://news.google.com/search'
params = {'hl': 'ja', 'gl': 'JP', 'ceid': 'JP:ja', 'q': keyword}
res = requests.get(url, params=params)
print(res.text)
time.sleep(60 * 3) #Maybe it's better to leave a proper interval?
def random_string(n):
return ''.join(random.choices(string.ascii_letters + string.digits, k=n))
def main():
win = tk.Tk()
app = Application(master=win)
app.mainloop()
if __name__ == "__main__":
main()
Recommended Posts