简体   繁体   中英

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

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)

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 !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM