如何更新 pyautogui 中的按钮

发布于 2025-01-09 04:33:51 字数 2536 浏览 0 评论 0原文

我尝试修改文件来改进程序,直到遇到障碍。

如何更新/重新启动 pyAutoGui 中的按钮?

如果您想修复它,这是迷你代码。 还请介绍一下它是如何工作的。

我想修改这个程序,因为原来的程序是《我的世界》的骗局。我想修复它,以便我可以调整点击延迟并能够更改键绑定,因为默认值是 ALT,仅此而已。

import keyboard
import win32api, win32con
import threading
import pyautogui
import PySimpleGUI as sg

#For default key bind

key = 'alt'
def main():
#To loop everytime you want to change keybind
   def keybind(key, Duping):
           while True:
               return key.hotkeys['\t', '\n', '\r', ' ', '!', '"', '#', '$', '%', '&', "'", '(',
')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`',
'a', 'b', 'c', 'd', 'e','f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~',
'accept', 'add', 'alt', 'altleft', 'altright', 'apps', 'backspace',
'browserback', 'browserfavorites', 'browserforward', 'browserhome',
'browserrefresh', 'browsersearch', 'browserstop', 'capslock', 'clear',
'convert', 'ctrl', 'ctrlleft', 'ctrlright', 'decimal', 'del', 'delete',
'divide', 'down', 'end', 'enter', 'esc', 'escape', 'execute', 'f1', 'f10',
'f11', 'f12', 'f13', 'f14', 'f15', 'f16', 'f17', 'f18', 'f19', 'f2', 'f20',
'f21', 'f22', 'f23', 'f24', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9',
'final', 'fn', 'hanguel', 'hangul', 'hanja', 'help', 'home', 'insert', 'junja',
'kana', 'kanji', 'launchapp1', 'launchapp2', 'launchmail',
'launchmediaselect', 'left', 'modechange', 'multiply', 'nexttrack',
'nonconvert', 'num0', 'num1', 'num2', 'num3', 'num4', 'num5', 'num6',
'num7', 'num8', 'num9', 'numlock', 'pagedown', 'pageup', 'pause', 'pgdn',
'pgup', 'playpause', 'prevtrack', 'print', 'printscreen', 'prntscrn',
'prtsc', 'prtscr', 'return', 'right', 'scrolllock', 'select', 'separator',
'shift', 'shiftleft', 'shiftright', 'sleep', 'space', 'stop', 'subtract', 'tab',
'up', 'volumedown', 'volumemute', 'volumeup', 'win', 'winleft', 'winright', 'yen',
'command', 'option', 'optionleft', 'optionright']

            #A condition which the program starts, so it needs to be left.
               if event == (empty):
                   break

   #For a hotkey and a button    
   layout = [sg.Text('Set Hotkey to run: '), sg.Button(key.upper())],



      #Window and Event
   window = sg.Window('Window', layout, size=(450, 250), font='bold')
   while True:
       event, values = window.read()
       if event == 'key.upper()':
                   key = keybind(key, (empty))

I tried to modify a file to improve the program until I met a roadblock.

How do you update/restart a button in pyAutoGui?

This is the mini-code if you would like to fix it.
Please also present how it works.

I wanted to modify the program since the original is a dupe for Minecraft. I want to fix it so that I can adjust the delay for clicks and be able to change the keybind since the default is ALT and nothing more.

import keyboard
import win32api, win32con
import threading
import pyautogui
import PySimpleGUI as sg

#For default key bind

key = 'alt'
def main():
#To loop everytime you want to change keybind
   def keybind(key, Duping):
           while True:
               return key.hotkeys['\t', '\n', '\r', ' ', '!', '"', '#', '
, '%', '&', "'", '(',
')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`',
'a', 'b', 'c', 'd', 'e','f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~',
'accept', 'add', 'alt', 'altleft', 'altright', 'apps', 'backspace',
'browserback', 'browserfavorites', 'browserforward', 'browserhome',
'browserrefresh', 'browsersearch', 'browserstop', 'capslock', 'clear',
'convert', 'ctrl', 'ctrlleft', 'ctrlright', 'decimal', 'del', 'delete',
'divide', 'down', 'end', 'enter', 'esc', 'escape', 'execute', 'f1', 'f10',
'f11', 'f12', 'f13', 'f14', 'f15', 'f16', 'f17', 'f18', 'f19', 'f2', 'f20',
'f21', 'f22', 'f23', 'f24', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9',
'final', 'fn', 'hanguel', 'hangul', 'hanja', 'help', 'home', 'insert', 'junja',
'kana', 'kanji', 'launchapp1', 'launchapp2', 'launchmail',
'launchmediaselect', 'left', 'modechange', 'multiply', 'nexttrack',
'nonconvert', 'num0', 'num1', 'num2', 'num3', 'num4', 'num5', 'num6',
'num7', 'num8', 'num9', 'numlock', 'pagedown', 'pageup', 'pause', 'pgdn',
'pgup', 'playpause', 'prevtrack', 'print', 'printscreen', 'prntscrn',
'prtsc', 'prtscr', 'return', 'right', 'scrolllock', 'select', 'separator',
'shift', 'shiftleft', 'shiftright', 'sleep', 'space', 'stop', 'subtract', 'tab',
'up', 'volumedown', 'volumemute', 'volumeup', 'win', 'winleft', 'winright', 'yen',
'command', 'option', 'optionleft', 'optionright']

            #A condition which the program starts, so it needs to be left.
               if event == (empty):
                   break

   #For a hotkey and a button    
   layout = [sg.Text('Set Hotkey to run: '), sg.Button(key.upper())],



      #Window and Event
   window = sg.Window('Window', layout, size=(450, 250), font='bold')
   while True:
       event, values = window.read()
       if event == 'key.upper()':
                   key = keybind(key, (empty))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱要勇敢去追 2025-01-16 04:33:51

朋友你的代码不完整。

如果要更新按钮使用示例:

#Example 1:
if event == 'Button_event':
                window['Button_event'].update(disabled=True)
    #Disable the button
    
#Example 2:
    window['status'].update(background_color='#DAA520')
    #update color
    
#Example 3:
        window['status'].update('CONFIRM NUMBER')
        #update the text
    
#Example 4:
        window['status'].update(text_color='#000000') #Blue
        #updates the text color.
    

我不知道是否是这样,但如果是,它会有所帮助。

Friend your code is not complete.

If to update a button use example:

#Example 1:
if event == 'Button_event':
                window['Button_event'].update(disabled=True)
    #Disable the button
    
#Example 2:
    window['status'].update(background_color='#DAA520')
    #update color
    
#Example 3:
        window['status'].update('CONFIRM NUMBER')
        #update the text
    
#Example 4:
        window['status'].update(text_color='#000000') #Blue
        #updates the text color.
    

I don't know if that's it, but if it is, it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文