This doesn't produce a window and I don't know why

馋奶兔 提交于 2020-01-05 04:21:07

问题


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

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.

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)

回答1:


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.

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 !



来源:https://stackoverflow.com/questions/39596524/this-doesnt-produce-a-window-and-i-dont-know-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!