【问题标题】:pyinstaller failed to execute script , a simple script that worked with idlepyinstaller 无法执行脚本,这是一个与 idle 一起使用的简单脚本
【发布时间】:2020-11-20 22:07:29
【问题描述】:

我制作了一个小工具来将 ctrl+win+right 箭头绑定到此代码中的一个键,它的 F2 问题是当我尝试使用 pyinstaller 使其成为我想要这个工具的朋友的可执行文件时,当我尝试打开它说执行脚本失败的exe。但它适用于 python idle 代码是:

from pynput.keyboard import Key , Controller

keyboard = Controller()

i=2

import keyboard
import time
def waitUntil(): #defines function
    wU = True
    while wU == True:
        if not keyboard.is_pressed("F2"): #checks the condition
            wU = False
        else:
            wU = True

while i == 2 :
    if keyboard.is_pressed("F2") :
        waitUntil()
        keyboard.press("Ctrl+cmd+Right")
        keyboard.release("Ctrl+cmd+Right")```

【问题讨论】:

    标签: python pyinstaller py2exe


    【解决方案1】:

    这里很难提供帮助,因为最终 Controller 没有名为“is_pressed()”的方法。

    这样清理你的代码:

    from pynput.keyboard import Controller
    
    keyboard = Controller()
    
    def waitUntil(): #defines function
        wU = True
        while wU == True:
            if not keyboard.is_pressed("F2"): #checks the condition
                wU = False
            else:
                wU = True
    
    while True :
        if keyboard.is_pressed("F2") :
            waitUntil()
            keyboard.press("Ctrl+cmd+Right")
            keyboard.release("Ctrl+cmd+Right")
    

    运行时会出现以下错误:

    Traceback (most recent call last):
      File "/home/oubnouquestion.py", line 14, in <module>
        if keyboard.is_pressed("F2") :
    AttributeError: 'Controller' object has no attribute 'is_pressed'
    

    至少这是我在 Linux 上使用最新版本的 pynput 得到的。因此,它甚至在我使用 Pyinstaller 之前就坏了。你确定这在空闲时有效吗?

    【讨论】:

    • 我很确定我不知道为什么它对你不起作用,但你有其他选择吗
    • ps:我有 Windows 10
    猜你喜欢
    • 1970-01-01
    • 2019-08-03
    • 2021-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多