Button to Background in PYMT
Posted: 13 February 2012 01:13 AM   [ Ignore ]
Rank
Joined  2012-01-07
Total Posts:  11
New Member

The Background is working fine but i wanted to add a button and it is giving me errors. Please anyows who knows how to fix it should please give me some idea. here is the Code.

import math
from pymt import 
*
from OpenGL.GL import *


class 
Background(MTWidget):
    
def __init__(self):
        
super(Backgroundself).__init__()
        
self.background Image('background.jpg')

    
button1=MTButton(pos = (200200), size = (80,80), label='Button')
    
button2=MTButton(pos = (200,200), size = (80,80), label='Button')
    
    
Background.add_widget(button1)
    
Background.add_widget(button2)



    
def draw(self):
        
getWindow()
        
w.gradient False
        set_color
(111)
        
drawTexturedRectangle(self.background.texturesize=w.size)

        
h2 w.height 2.
        l 
[]
        l2 
[]
        t 
getClock().get_time()
        for 
x in xrange(0w.width 5050):
            
l.append(x)
            
l.append(h2 120 math.sin(0.01 0.3) * 30
            
l.append(x)
            
l.append(h2 120 math.sin(0.01 0.01 0.15) * 30
            
l2.append(x)
            
l2.append(h2 200 math.cos(0.01 0.2) * 30
            
l2.append(x)
            
l2.append(h2 140 math.cos(0.01 0.01 0.3) * 30
        
set_color(65 255.123 255.161 255..2
        
drawPolygon(lstyle=GL_TRIANGLE_STRIP)
        
drawPolygon(l2style=GL_TRIANGLE_STRIP)


if 
__name__ == '__main__':
  
runTouchApp(Background())

 Signature 

Emmanuel Amuno
Leodtech.blogspot.com
University of Saint Joseph

Profile
 
 
Posted: 15 February 2012 04:47 PM   [ Ignore ]   [ # 1 ]
Avatar
Rank
Joined  2010-04-04
Total Posts:  29
New Member

To add anything to a class itself use “self.add_widget()” and you have to define and add the buttons when the app is initializing in init()

def __init__(self):
        
super(Backgroundself).__init__()
        
self.background Image('background.jpg')

        
button1=MTButton(pos = (200200), size = (80,80), label='Button')
        
button2=MTButton(pos = (200,200), size = (80,80), label='Button')
    
        
self.add_widget(button1)
        
self.add_widget(button2)

Profile
 
 
Posted: 15 February 2012 09:52 PM   [ Ignore ]   [ # 2 ]
Rank
Joined  2012-01-07
Total Posts:  11
New Member

Thanks Fantastable....I do appreciate it.

 Signature 

Emmanuel Amuno
Leodtech.blogspot.com
University of Saint Joseph

Profile
 
 
   
 
 
‹‹ Help      Config Window ››