我想在Python中画一条线,但是当我运行下面的代码时,这条线永远不会出现。事实上,我需要创建一个包含4x4段的字段,但让我们从一行开始。 我的代码:
import sys, pygame
from pygame.locals import*
width=1000
height=500
Color_screen=(49,150,100)
Color_line=(255,0,0)
def main():
screen=pygame.display.set_mode((width,height))
screen.fill(Color_screen)
pygame.display.flip()
pygame.draw.line(screen,Color_line,(60,80),(130,100))
while True:
for events in pygame.event.get():
if events.type == QUIT:
sys.exit(0)
main()
出了什么问题?
答案 0 :(得分:2)
绘制线后,您必须使用pygame.display.flip
更新计算机的显示。
pygame.draw.line(screen, Color_line, (60, 80), (130, 100))
pygame.display.flip()
通常每帧一次在while循环的底部完成。
答案 1 :(得分:0)
绘制线条后执行pygame.display.flip()即可:
screen.fill(color)
pygame.display.flip()
pygame.draw.line(...)
问题在于您需要先显示所有内容,然后才能显示出来。 改为这样做:
screen.fill(color)
pygame.draw.line(...)
pygame.display.flip()
答案 2 :(得分:0)
添加
pygame.display.flip()
画好线后。
答案 3 :(得分:0)
尝试给线一个宽度(线方法的最后一个参数)并更新显示
public class AnotherUnmarshalling {
public static void main(String[] args) throws XMLStreamException, JAXBException {
final InputStream inputStream = Unmarshalling.class.getClassLoader().getResourceAsStream("customer.xml");
final XMLStreamReader xmlStreamReader = XMLInputFactory.newInstance().createXMLStreamReader(inputStream);
final Unmarshaller unmarshaller = JAXBContext.newInstance(AnotherCustomer.class).createUnmarshaller();
final AnotherCustomer customer = unmarshaller.unmarshal(xmlStreamReader, AnotherCustomer.class).getValue();
System.out.println(customer.toString());
}
}