是否可以在不创建pygame窗口,表面或GUI的情况下运行pygame?我想利用某些pygame函数,但是我不想弹出GUI。
例如,除非我在pygame中设置了一个窗口,否则此功能将不起作用。
running = True
def mainloop():
while True:
for event in pygame.event.get():
if ( event.type == pygame.QUIT ) or \
( event.type == pygame.KEYDOWN and \
( event.key == pygame.K_ESCAPE) ):
running = False
print "quit"
pygame.quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN:
print "working"
Run Code Online (Sandbox Code Playgroud) 我正在教自己如何通过编写我在youtube上找到的简单的面部识别程序来使用openCV.我已经安装了opencv版本2以及numpy 1.8.0.我正在使用python2.7.
我在下面的视频和文章链接中准确地复制了这段代码,但我一直在收到错误.AttributeError:'module'对象没有属性'cv'我做错了什么?
这是我正在使用的代码.
import cv2
import sys
# Get user supplied values
imagePath = sys.argv[1]
cascPath = sys.argv[2]
# Create the haar cascade
faceCascade = cv2.CascadeClassifier(cascPath)
# Read the image
image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Detect faces in the image
faces = (faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags = cv2.cv.CV_HAAR_SCALE_IMAGE)
)
print "Found {0} faces!".format(len(faces))
# Draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.rectangle(image, (x, y), (x+w, y+h), (0, …Run Code Online (Sandbox Code Playgroud) 如果我将pygame窗口设置为可调整大小,然后单击并拖动窗口的边框,窗口将变大,但表面上的任何blit都不会随之变大.(这是可以理解的)我怎么做到这样,当我调整窗口大小时,所有blit对象调整大小并正确填充窗口?
例如:假设我有一个200 x 200的窗口,我在window_width/2和window_height/2处按下了一个按钮.按钮将位于窗口的中心,为100 x 100.现在,如果我将窗口调整为300 x 300,则按钮将保持为100 x 100而不是150 x 150.
我试过搞乱pygame.Surface.get_width等,但没有运气.基本上我正在尝试调整程序窗口的大小,并使所有blit图像保持成比例.
我知道如何将对象与.append和.extend等组合在一起,但我无法弄清楚如何将列表中的单个对象组合到一个对象中.
例.
我该如何更改此列表:List = ["h","e","l","l","o"]
进入此列表:List = ["hello"]