GUI help

Hi

I started with panda last week and everything was fine until I try to create a GUI. I’ve been searching and I was able to create a button and to add a command to it, but I’m not able to create a good ‘interface’ for it.

self.frame = DirectFrame(
                geom = self.menuGraphics.find('**/MenuMod'),
                relief = None, scale = (0.6,1,0.6),
                frameColor = (1,1,1,0.75),
                pos = (0.2625,0,0.43125), parent = base.aspect2d)
        
        button  = DirectButton(relief = None, 
                text = ("ready", "clicked", "roll", "disabled"), 
                text_scale = 0.2,

                geom = (self.menuGraphics.find('**/BotaoReady'),
                            self.menuGraphics.find('**/BotaoIdle'),
                            self.menuGraphics.find('**/BotaoActive'),
                            self.menuGraphics.find('**/BotaoDesable')))
        button.reparentTo(self.frame)

With this code I’m able to create the button but im not able to create the frame (the thing behind the button).

http://img855.imageshack.us/g/botaoactive.jpg/

http://img855.imageshack.us/img855/3018/botaoactive.jpg
http://img856.imageshack.us/img856/5034/botaodesable.jpg
http://img856.imageshack.us/img856/4724/botaoidle.jpg
http://img861.imageshack.us/img861/8923/botaoready.jp
http://img852.imageshack.us/img852/6880/menumod.jpg

I’m using these jpg images to create an .egg and the menu, but the result isnt what i want

Uploaded with ImageShack.us

1: Why the ‘menu background’ isnt there?
2: Why its so ugly?
3: What can I do to create a nice menu?

Thanks for your help
:smiley:

ps: sry for my enligh :smiley: :smiley: :smiley:

Hi! Welcome to the forums! I don’t understand the problem exactly, could you elaborate please? And if you post a (small) complete example which reproduces your problem we can experiment with that.

@Matkod

DirectGui widgets have an attribute called “frameSize”. This takes a list of 4 elements: [left, right, bottom, top]. So if you want a 1 unit high, 1 unit wide frame with the center in the middle of the frame, then it would look like this:

DirectFrame(frameSize = [-0.5, 0.5, -0.5, 0.5])

Note that first and third elements are negative. If they weren’t, the frame would be of 0 with and height.

If you wanted the frame to have the center in its upper left corner, than you would simply set the first and fourth elements to zero. You can basically put the center anywhere, which is useful for aligning stuff.

Anyway, the frameSize is probably what you’re looking for. Neither the “geom” nor the “scale” attribute can replace it, because they’re meant for a different purpose.

thx for the replies ^^

@ yaio

i need a window with frame and some buttons inside , but for some reason the button is so big that it hides the frame(i just discovered it now, whe i frist post i didnt know the frame was behind the button).

http://www.4shared.com/file/w_qPpWj7/main.html

this is the egg file for the menu

#Python imports...
import sys

#Panda3d imports...
import direct.directbase.DirectStart
from direct.actor.Actor import Actor
from direct.gui.DirectGui import OnscreenText
from direct.showbase.DirectObject import DirectObject
from panda3d.core import PandaNode,NodePath,Camera,TextNode
from pandac.PandaModules import WindowProperties 
from direct.gui.DirectGui import *
from pandac.PandaModules import *
from direct.filter.CommonFilters import CommonFilters


#Meus imports...
#from character import Character


class World(DirectObject):
    '''
        Uma classe para servir de Top level.
    '''

    def __init__(self):
        
        self.title = OnscreenText(text="Teste",
                                    style=1, fg=(1,1,1,1),
                                    pos=(0.95,-0.95), scale = .07)
        
        base.setFrameRateMeter(True) #Show FPS
        
        props = WindowProperties()
        props.setTitle('Teste Jogo 3D Panda3D Engine - Python') ##Criar titulo para janela
        base.win.requestProperties(props)
                
        
        self.filters = CommonFilters(base.win, base.cam)
        filterok = self.filters.setBloom(blend=(0,0,0,1),
                                         desat=-0.5, intensity=3.0, size=2)
        
        render.setShaderAuto()
        
        #self.character = Character()
        
        '''
        ## Luz (Lembrar de mudar isso depois)
        ambientLight = AmbientLight("ambientLight")
        ambientLight.setColor(Vec4(.3, .3, .3, 1))
        directionalLight = DirectionalLight("directionalLight")
        directionalLight.setDirection(Vec3(-5, -5, -5))
        directionalLight.setColor(Vec4(1, 1, 1, 1))
        directionalLight.setSpecularColor(Vec4(1, 1, 1, 1))
        render.setLight(render.attachNewNode(ambientLight))
        render.setLight(render.attachNewNode(directionalLight))
        '''
        #Load

        self.loadModels()

        self.keyBinds()

        taskMgr.doMethodLater(30, self.debug, 'debug')
        

    def debug(self, task):
        print (taskMgr)
        return task.again

    def loadModels(self):
        '''
            Carrega todos os Models.
        '''
        
        print ('Carregando Models....')

        
        self.terrain = loader.loadModel('models/world.egg')
        self.terrain.reparentTo(render)
        self.terrain.setPos(0,0,0)
        #self.terrain.setScale(10)
               
        
        self.menuGraphics = loader.loadModel('models/main')
        
        
    def keyBinds(self):
        self.accept('escape', sys.exit)
        self.accept('x', self.menustart)
        

    def menustart(self):
        self.frame = DirectFrame(
                geom = self.menuGraphics.find('**/MenuMod'),
                relief = None, scale = (0.6,1,0.6),
                frameColor = (1,1,1,0.75),
                pos = (0.2625,0,0.43125),
                parent = base.aspect2d)
        
        button = DirectButton(relief = None, 
                text = ("ready", "clicked", "roll", "disabled"), 
                text_scale = 0.2,

                geom = (self.menuGraphics.find('**/BotaoReady'),
                            self.menuGraphics.find('**/BotaoIdle'),
                            self.menuGraphics.find('**/BotaoActive'),
                            self.menuGraphics.find('**/BotaoDesable')))
        button.reparentTo(self.frame)
        

        
        
w = World()
run()

@ coppertop

I tried frameSize but i got nothing diferent :open_mouth:
but because of u i discovered that the frame was behind the button :smiley:

What I want is a simple frame with some buttons (New Game, Options, Quit Game)that when I press a key they show and when i press again they hide

Why didn’t you scale the button? With a code like this:

button = DirectButton( [...]
  scale = ( .6, 1, .2 ),
[...] )

I obtain the expected result.

omg :blush:

thx man i firgot about scale the button i was just scaling the frame =S

i guess its solved :smiley: