Я ищу способ запустить цикл while при нажатии кнопки в этом случае с кнопкой «start_loop». Я очень хотел бы знать, как это делается, и будет признателен за любую помощь в завершении этого благодарения!Как запустить цикл while нажатием кнопки GUI?
Вот полный Python сценария:
from tkinter import *
import win32api
import win32con
from tkinter import messagebox
# defining click as setting the position and starting a click and ending a click
def click(x, y):
win32api.SetCursorPos((x, y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
# Creation of the GUI below
root = Tk()
root.geometry('315x250+250+250') # 315x250 and 250 pixels in x and y direction
root.title("Buffet Time's Auto-Clicker")
# Click
click_label = Label(text='Enter # of clicks here:', fg='green').place(x=30, y=30)
click_entry = Entry().place(x=150, y=30)
# X
x_label = Label(text='Enter the x coordinate here:', fg='black').place(x=30, y=75)
x_entry = Entry().place(x=150, y=75)
# Y
y_label = Label(text='Enter the y coordinate here:', fg='blue').place(x=30, y=120)
y_entry = Entry().place(x=150, y=120)
# Start the loop button
start_loop = Button(text='Press to Start', fg='yellow', bg='black').place(x=110, y=175)
# prompts user before quitting
def on_closing():
if messagebox.askokcancel("Quit", "Do you want to quit?"):
root.destroy()
root.protocol("WM_DELETE_WINDOW", on_closing)
root.mainloop()
num_of_clicks = click_entry.get()
x_coord = x_entry.get()
y_coord = y_entry.get()
# while loop for the clicking
counter = 0
try:
while counter < num_of_clicks:
click(x_coord, y_coord) # 230, 475 for cookie clicker
if win32api.GetAsyncKeyState(ord('X')):
break
counter += 1
except KeyboardInterrupt:
pass
Что я пытаюсь сделать, так это сделать этот GUI, который имеет вход для каждой из трех переменных в цикле while, а затем автоматический кликер запускается после нажатия кнопки «Нажмите, чтобы Начать ", после чего он будет продолжать нажимать до тех пор, пока не будет сделано ни число кликов, ни нажатие клавиши« X », которая убивает цикл. Оттуда я могу вставить цикл while в кнопку, чтобы при нажатии кнопки цикл While работал? –
Похоже, вам нужны две темы - извините, мой Python не до этого! – JonP