[英]Pygame not displaying the window
我有一個名為紙牌的文件夾,其中有png紙牌圖像H,D,C和S 01-13。 下面的卡發行商代碼可在Raspbian下的Raspberry Pi上運行,但在Pycharm(Python 3.4)中運行時,它將執行所有操作,但不顯示窗口。 我已經在每個部分中放入了調試打印語句(現已刪除),以檢查它是否完成了所有工作。 有什么線索嗎?
# prompts to play/quit and for hand size and no of players
#
import random
import pygame
pygame.init()
def main():
myvar = input("Press P to Play or Q to Quit ")
if myvar =="p" or myvar=="P":
getimage()
else:
quit()
def getimage():
n_players = int(input("How many players? "))
hand_size = int(input("How many cards in a hand? "))
if n_players * hand_size > 52:
print("There are only 52 cards, cannot do.")
main()
#card suit and rank lists
suits = 'S H D C'.split()
ranks = '01 02 03 04 05 06 07 08 09 10 11 12 13'.split()
#generate deck of pngs by list comprehension
pathw = "cards/"
deck = [pathw + s + r + ".png" for r in ranks for s in suits]
#create Surface as "screen"
cardw = 77 #actual width = 71
cardh = 120 #actual width = 96
screen=pygame.display.set_mode([cardw * hand_size, cardh * n_players])
#set background colour
GREEN = (0,102,0)
screen.fill(GREEN)
random.shuffle(deck)
hands = deal(deck, n_players, hand_size, cardw)
#remove quotes and brackets from string
c=0
while c < n_players:
player1 = str(hands[c])
player1 = player1.strip("['")
player1 = player1.strip("']")
slicep1 (player1, cardw, cardh, c)
c +=1
pygame.display.update()
main()
def slicep1 (player1, cardw, cardh, c):
pics = player1.split("', '")
count = 0
for pic in pics:
showcards(pic, cardw, cardh, c, count)
count += 1
def deal(deck, n_players, hand_size, cardw):
return [deck[i * hand_size:(i+1) * hand_size] for i in range(n_players)]
def showcards(pic, cardw, cardh, c, count):
pic1 = pygame.image.load(pic)
main_surface = pygame.display.get_surface()
main_surface.blit(pic1, (count*cardw+1, c*cardh+1))
main()
下面的發卡機構代碼可在Raspbian下的Raspberry Pi上運行,但在Pycharm(Python 3.4)中運行時,它將執行所有操作,但不顯示任何窗口。
我猜想PyCharm(Python 3.4)注釋意味着它不在Raspberry Pi上運行。 如果是這種情況,那么看來您在PyCharm(Python 3.4)上的環境有問題。
我的猜測是您的Python 3.4與安裝的Pygame版本不兼容。 例如,當您確實需要3.4 msi(如果正在運行Windows)時,您下載並安裝了pygame-1.9.2a0.win32-py3.2.msi 。
另一種可能性是您正在運行64位版本的Python,並且已安裝32位版本的Pygame。
希望對您有所幫助。 在不知道其他環境正在運行什么版本的Python和Pygame的情況下,我無法給出更明確的答案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.