这不会产生窗户,我也不知道为什么 [英] This doesn't produce a window and I don't know why

查看:149
本文介绍了这不会产生窗户,我也不知道为什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VPython来模拟从墙上弹起的球.

I am using VPython in my attempt to model a ball bouncing off a wall.

为了使我的代码更优雅,我决定使用类继承来设置对象的尺寸和属性(此刻,它是球和一堵墙).运行代码后,shell没有产生任何错误,但是,它也没有产生窗口.

To make my code more elegant, I have decided to use class inheritance to set the dimensions and properties of my objects (at the moment, it's the ball and a wall). After I ran the code, the shell didn't produce any errors, however, it did not produce a window either.

我对编程还很陌生,我在Linux Mint 18上的Wine中使用VPython 2.7.我有一种感觉,我错过了一些显而易见的东西,但我不知道它是什么.

I am fairly new to programming and I am using VPython 2.7 in Wine on Linux Mint 18. I have a feeling that I have missed something obvious but I don't know what it is.

到目前为止,我的代码如下:

My code so far is as follows:

from visual import *

class Obj(object):

def __init__(self, pos, color): #sets the position and color
         self.pos = pos
         self.color = color

class Sphere(Obj):

    def __init__(self, pos, color, radius):
        super(Sphere, self).__init__(pos, color)
        self.radius = radius

class Box(Obj):

    def __init__self, pos, color, radius):
        super(Box, self).__init__(pos, color)
        self.size = size
        self.opacity = opacity


ball1 = Sphere((-5,0,0,), color.orange, 0.25)
wallR = Box((6,0,0), color.cyan, (0.,12,12), 0.3)

推荐答案

我认为您以前从未处理过图形方面的问题,因为您发布的代码中没有涉及图形方面的内容.然后是时候开始了! 默认情况下,python在控制台模式下工作.要显示带有图标和内容的实际窗口,您需要使用 TKinter pygame 之类的模块在代码中明确地编写它.

I take it you never dealt with graphic aspects before, as there is nothing about it in the code you posted. Then it is time to begin ! By default, python works in console mode. To show an actual window, with icons and stuff going across it, you'll need to write it explicitly in your code, using modules like TKinter or pygame.

我建议您阅读在这里找到的教程: http://code .activestate.com/recipes/502241-bouncing-ball-simulation/进行操作(使用 TKinter ),包括窗口部分.看一看,看看是否仍然需要帮助!

I suggest you read the tutorial I found here : http://code.activestate.com/recipes/502241-bouncing-ball-simulation/ as it does what you want (with TKinter), including the window part. Take a look at it and let's see if you still need help !

这篇关于这不会产生窗户,我也不知道为什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆