我的游戏背景是一幅图像,唯一的问题是出现两个窗口,我只想要一个。出现两个窗口,一个窗口很小,带有图像,另一个窗口很大,但是没有任何图像。我该怎么做才能使两者一起工作?代码:
import pygame
from pygame.locals import *
from Tkinter import *
import Tkinter as Tk
black = ("#000000")
white = ("#FFFFFF")
green = ("#00CD00")
yellow = ("#FFFF00")
pygame.init()
display = pygame.display.set_mode((1024,720))
pygame.display.set_caption("Hello Universe")
root = Tk.Tk()
background_image=Tk.PhotoImage(file="/home/jar/python/background_image.gif")
background_label = Tk.Label(root, image=background_image)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
root.mainloop()
quit = False
while not quit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit = True
答案 0 :(得分:0)
结果证明您不需要Tkinter,只需执行以下操作:
import pygame
from pygame.locals import *
pygame.init()
white = (255,255,255)
size = [1024, 720]
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Hello Universe")
done = False
clock = pygame.time.Clock()
background_image = pygame.image.load("background_image.gif").convert()
while done == False:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
screen.blit(background_image, [0,0])
pygame.display.flip()
clock.tick(60)