小编GLH*_*LHF的帖子

pyautogui.locateCenterOnScreen()返回None而不是坐标

import pyautogui
print (pyautogui.locateCenterOnScreen("C:\Users\Venkatesh_J\PycharmProjects\mouse_event\mouse_event.png"))
Run Code Online (Sandbox Code Playgroud)

它返回而不是返回坐标None.

python python-3.4 pyautogui

17
推荐指数
2
解决办法
6034
查看次数

如何在'while'循环中返回错误后返回特定点

我正在尝试编写一个包含while循环的程序,在这个循环中,如果出现问题,我会收到错误消息.有点像这样;

while True:

    questionx = input("....")
    if x =="SomethingWrongabout questionX":
        print ("Something went wrong.")
        continue
    other codes...

    questiony = input("....")
    if y == "SomethingWrongabout questionY":
        print ("Something went wrong.")
        continue

    other codes...

    questionz = input("....")
    if z == "SomethingWrongabout questionZ":
       print ("Something went wrong.")
       continue

    other codes..
Run Code Online (Sandbox Code Playgroud)

问题如下:当发生错误后questionX,程序进入开始状态.它从头开始,而不是从yz.但是,x没有问题,因此,程序应该开始提出问题yz因为,问题发生在yz.

如何使程序从特定点开始,如果只有y问题出错,程序必须开始提问y或者只是在z,程序必须从头开始z,而不是从头开始x.

我应该while为此使用多个循环,还是有任何东西只能在一个循环中使用?

python loops continue while-loop python-3.x

13
推荐指数
2
解决办法
1555
查看次数

如何从BeautifulSoup中的span标签获取文本

我的链接看起来像这样

<div class="systemRequirementsMainBox">
<div class="systemRequirementsRamContent">
<span title="000 Plus Minimum RAM Requirement">1 GB</span> </div>
Run Code Online (Sandbox Code Playgroud)

我想1 GB从那里开始.我试过了

tt  = [a['title'] for a in soup.select(".systemRequirementsRamContent span")]
for ram in tt:
    if "RAM" in ram.split():
        print (soup.string)
Run Code Online (Sandbox Code Playgroud)

它输出None.

我试过a['text']但它给了我KeyError.我怎么能解决这个问题,我的错误是什么?

python beautifulsoup web-scraping python-3.4

8
推荐指数
2
解决办法
2万
查看次数

Pygame捕捉Enter按钮

我试图用pygame捕捉Enter按钮,而不是键盘上的Enter按钮,我想要的是Backspace按钮下的Enter按钮.它们不相同,因为当我在键盘上按下Enter按钮时,其他Enter按钮不起作用.

http://www.pygame.org/docs/ref/key.html

有一个关于键的文档,但只有键盘输入按钮.我试过这些代码:

这适用于键盘输入按钮,但其他输入按钮不起作用:

if event.type==pygame.KEYDOWN:
    if event.key==pygame.K_KP_ENTER:
        #some codes
Run Code Online (Sandbox Code Playgroud)

我试图用这些代码捕捉另一个Enter按钮(绝望):

if event.type==pygame.KEYDOWN:
    if event.key==pygame.K_ENTER:
        #some codes
Run Code Online (Sandbox Code Playgroud)

但当然会出现错误:

AttributeError: 'module' object has no attribute 'K_ENTER'
Run Code Online (Sandbox Code Playgroud)

无法弄清楚如何在Backspace下捕获Enter按钮.

python windows pygame python-3.x

6
推荐指数
2
解决办法
7244
查看次数

如何在Pygame中获取用户的输入并将其保存为变量?

我的想法是我想从游戏中的用户那里得到一些输入,比如用户的名字,然后我想把它放在屏幕上.也许在开始游戏或游戏中间之前,这很重要.

我尝试过InputBox等,但它实际上并没有工作,我尝试了一些像这样的模块,但没有工作,有些只是在屏幕上输入我的文字就是这样,我想要的是我想要输入并放置一些地方在pygame屏幕上.

所以我必须将该输入保存为变量.是否有任何可能的方法来执行此操作?

例:

font1 = pygame.font.SysFont("None", 30)
score=0
text=font1.render("{}".format(score), True,(255,255,255))
...
...
if sneakeattheapple:
    score += 1
    text=font1.render("{}".format(score), True,(255,255,255))
...
...
screen.blit(text,(275,6))
Run Code Online (Sandbox Code Playgroud)

这将把得分变量放在屏幕上,然后当我想像在蛇游戏中更新得分时,偷偷吃苹果我可以更新文本,这样我就可以更新得分变量.但这个得分变量已经定义,我想要使用用户给出的变量来做到这一点.

编辑:我已经检查了所有答案和问题,这些不是我问的问题和我想要的.有一些方法可以打印这些变量,这不是我想要的,正如我所说.抓住键盘事件并打印它们不是我的问题的任何部分.我给出了"名字"的例子,但这个问题与我的问题没有关系

编辑2:让我更清楚.在Python中我们可以做到这一点;

x=input("Do you want to do this?(y/n): ")
if x=="y":
    #do something
if x=="n":
    #do something
Run Code Online (Sandbox Code Playgroud)

无论我们想要什么,我们都可以随时问这个问题.这就是我想在Pygame中做的事情.

python pygame input python-3.4

6
推荐指数
3
解决办法
1万
查看次数

在Windows下获取系统信息(CPU速度 - 总RAM-图形卡模型等)

我搜索了很多但找不到任何有用的东西.这有可能获得系统信息;

CPU: Intel Core i7-3770K CPU @3.5Ghz
RAM: 8GB
Graphic Card: NVIDIA GeForce GTX 680
Run Code Online (Sandbox Code Playgroud)

在Windows下?我怎样才能达到这个输出?

编辑:platform.processor()没有给出我想要的输出.所以这对我来说毫无用处.

python windows system-information python-3.4

6
推荐指数
1
解决办法
6919
查看次数

Pycharm错误"进程已完成退出代码-1073740791(0xC0000409)"

我在Pycharm上有一个脚本测试,脚本工作大约3-4分钟,然后它说"Python停止工作",脚本停止运行.它说,在Pycharm输出部分Process finished with exit code -1073740791 (0xC0000409).

这是我的电脑/ Pycharm的错误或错误吗?

python nvidia pycharm windows-10 python-3.5

6
推荐指数
1
解决办法
7292
查看次数

Pyautogui TypeError:'NoneType'对象不可迭代

我正在尝试使用locateCenterOnScreen()PyAutoGUI的功能,但它引发了:

Traceback (most recent call last):
  File "C:\Users\windows\Desktop\asd.py", line 3, in <module>
    buttonx, buttony = pyautogui.locateCenterOnScreen('who.jpg')
TypeError: 'NoneType' object is not iterable
Run Code Online (Sandbox Code Playgroud)

我的代码是:

import pyautogui

buttonx, buttony = pyautogui.locateCenterOnScreen('who.jpg')
pyautogui.doubleClick(buttonx,buttony)
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

python python-3.4 pyautogui

5
推荐指数
1
解决办法
3613
查看次数

如何在PyQt5和小部件问题中禁用右键单击

我有一个简单的代码,正在制作一个带有工具栏的窗口。

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import sys

class AnaPencere(QMainWindow):
    def __init__(self):
        super().__init__()
        self.widget = QWidget(self)
        self.setCentralWidget(self.widget)

        self.toolBar = QToolBar(self)
        self.addToolBar(Qt.TopToolBarArea, self.toolBar)

        self.pushButton1 = QPushButton()
        self.pushButton1.setText("Open")
        self.toolBar.addWidget(self.pushButton1)

        self.toolBar.addSeparator()
        self.pushButton2 = QPushButton()
        self.pushButton2.setText("Save")
        self.toolBar.addWidget(self.pushButton2)

        self.pushButton3 = QPushButton()
        self.pushButton3.setText("Save as")
        self.toolBar.addWidget(self.pushButton3)
        #t = QToolBar(self)
        #t.setMovable(False)

uygulama = QApplication(sys.argv)
pencere = AnaPencere()
pencere.show()
uygulama.exec_()
Run Code Online (Sandbox Code Playgroud)

这将创建 3 个工具栏。但问题是,当我右键单击工具栏时,会弹出一个小窗口,当我单击该小窗口时,所有工具栏都消失了。如果我再次做同样的事情,工具栏又会回来。我不希望用户能够做类似的事情,所以我想如果我禁用右键单击它就会修复,但我不能。这里那个小窗户

在此输入图像描述

python windows qtoolbar python-3.4 pyqt5

3
推荐指数
1
解决办法
1800
查看次数

读取输入后隐藏控制台窗口

我有一个带有GUI的脚本,它接收用户数据并将其存储到文本文件中.它运行另一个脚本(.exe),等待用户输入然后执行一些操作.我想要的是后一个脚本在读取用户输入后隐藏其控制台窗口,但继续在后台工作.

我尝试用subprocess.call('lastscript.exe', shell=True)或运行该脚本subprocess.Popen('lastscript.exe', shell=True).这不起作用.我不得不采取从用户输入的第一个,然后隐藏控制台,让在后台的工作方案.

python windows windows-console python-3.4

3
推荐指数
1
解决办法
778
查看次数