当前位置: 首页>>代码示例>>Python>>正文


Python StackLayout.remove_widget方法代码示例

本文整理汇总了Python中kivy.uix.stacklayout.StackLayout.remove_widget方法的典型用法代码示例。如果您正苦于以下问题:Python StackLayout.remove_widget方法的具体用法?Python StackLayout.remove_widget怎么用?Python StackLayout.remove_widget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kivy.uix.stacklayout.StackLayout的用法示例。


在下文中一共展示了StackLayout.remove_widget方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Main

# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import remove_widget [as 别名]
class Main(App):

    height = 720
    width = (height/16) * 9
    Window.size = (width,height)
    
    def build(self):
        self.itu_lat = 55.6593807
        self.itu_lon = 12.5910774
        self.obs_dic = None        
        self.old_time = 0.0
        self.weatherbox = AnchorLayout(anchor_x = 'center', anchor_y = 'bottom')
        self.Layout = RelativeLayout()
        self.mapview = MapView(zoom=11, lat=self.itu_lat, lon=self.itu_lon)
        mapview = self.mapview
        self.Layout.add_widget(mapview)
        # add map layer
        self.jsonmap = GeoJsonMapLayer(source='5_mile_airport.json')
        self.mapview.add_layer(self.jsonmap)        



        
        self.overlay = AnchorLayout(anchor_x='right', anchor_y='top')
        lowerLeft = AnchorLayout(anchor_x='left', anchor_y='bottom')
        self.lowerLeftStack = StackLayout(orientation='lr-bt',size_hint=(0.15,0.15))
        lowerLeft.add_widget(self.lowerLeftStack)
        btnre = Button(background_normal='refocus_normal.png', background_down='refocus_down.png', size_hint = (2,1))
        btnre.bind(on_press=self.resetloc)        
        btnnf = ToggleButton(background_normal='nofly_normal.png', background_down='nofly_down.png',size_hint = (2,1))
        btnnf.bind(on_press=self.nofly)
        self.lowerLeftStack.add_widget(btnre)
        self.lowerLeftStack.add_widget(btnnf)
        
        
        btn = ToggleButton(background_normal='Settings B.png', background_down="Settings G.png")
        btn.bind(on_press= self.show_dropdown)
        self.settings = StackLayout(size_hint=(0.2,0.2))
        self.settings.add_widget(btn)
        self.overlay.add_widget(self.settings)
        self.Layout.add_widget(lowerLeft)
        self.Layout.add_widget(self.overlay)
        
        marker = MapMarker(anchor_x = 0.5, anchor_y = 0.5, lat=self.itu_lat, lon=self.itu_lon)
        self.mapview.add_marker(marker)        
         
        return self.Layout
        
        
    def resetloc(self,instance):
        self.mapview.center_on(self.itu_lat,self.itu_lon)
    
    def nofly(self,instance):
        if instance.state == 'down':
            self.mapview.remove_layer(self.jsonmap)
        else:
            self.mapview.add_layer(self.jsonmap)
        
    def show_dropdown(self,instance):
        if instance.state == 'down':
            size = (1,0.5)
            btn1 = ToggleButton(text='Weather', size_hint = size)
            btn2 = Button(text='Level',size_hint = size)
            btn3 = Button(text='Nearby\nusers', size_hint = size)

            btn1.bind(on_press = self.show_weather_data)             
            
            self.settings.add_widget(btn1)
            self.settings.add_widget(btn2)
            self.settings.add_widget(btn3)
        else:
            for child in self.settings.children[:]:
                if child.text != "":
                    self.settings.remove_widget(child)
    
    def show_weather_data(self,instance):  
        weatherbox = self.weatherbox
        if instance.state == 'down': 
            layout = BoxLayout(orientation='vertical', size_hint = (0.2,0.1) )
            clat = self.mapview.lat
            clon = self.mapview.lon        
            
            ctime = time.time()        
            
            if(self.obs_dic == None or ctime > (self.old_time + 0.5)):            
                self.old_time = ctime
                self.obs_dic = api.loc_weather(clat,clon)
                weList = self.obs_dic['weather']
                we = weList[0]
                wi = self.obs_dic['wind']            
                l1 = Label(text = 'Current weather: ' + we['main'], color = (0.,0.,0.,1))
                main = self.obs_dic['main']
                k = main['temp']
                #Conversion from imperial to metric
                temp = k-273.15
                l2 = Label(text = 'temp: ' + str(temp) + ' ' + u'\u00B0' + 'C', color = (0.,0.,0.,1))
                hu = main['humidity']
                l3 = Label(text = 'humidity: ' + str(hu) + '%', color = (0.,0.,0.,1))
                pre = main['pressure']
                l4 = Label(text = 'pressure' + str(pre) + ' hPa', color = (0.,0.,0.,1))
#.........这里部分代码省略.........
开发者ID:FlapKap,项目名称:Eyes4Drones,代码行数:103,代码来源:main.py

示例2: EyeTest

# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import remove_widget [as 别名]
class EyeTest(StackLayout):
    def __init__(self):
        super(EyeTest, self).__init__()
        self.cell = 2
        self.score = 0
        self.time = 15
        self.alpha = 0.2
        self.end = False
        self.btnList = []
        self.sizeHint = (.5, .45)
        self.layout = StackLayout()
        self.currentTime = time.time()
        self.luckyNumber = randint(0, 3)
        self.label = Button(text = 'Score: 0  Time - 15 sec.',
                            on_press = self.restart,
                            size_hint = (1, .1))

        self.add_widget(self.label)
        self.add_widget(self.layout)
        

    def checker(self, instance):
        if not self.end:
            # If chosen correct number
            if self.luckyNumber == int(instance.id):
                self.time = 15
                self.score += 1
                if self.cell < 5 and self.score % self.cell == 0:
                    self.cell += 1
                if self.score % 3 == 0 and self.alpha > 0.05:
                    self.alpha -= 0.01
                self.luckyNumber = randint(0, self.cell ** 2 - 1)
                self.sizeHint = (1 / self.cell, .9 / self.cell)

                # Delete old buttons
                for i in self.btnList:
                    self.layout.remove_widget(i)
                self.btnList = []

                self.addSetOfButton()

            # If chosen incorrect number
            else:
                self.time -= 3
                if self.time <= 0:
                    self.gameOver()
            
    def addSetOfButton(self):
        color = self.rgba()

        # Add new buttons
        for i in range(self.cell ** 2):
            btn = self.getButton(i, color)
            self.btnList.append(btn)
            self.layout.add_widget(btn)

        color[3] -= self.alpha
        # Change background_color random button
        btn = self.btnList[self.luckyNumber]
        btn.background_color = color

    def rgba(self):
        r, g, b = [random() for i in range(3)]
        return [r, g, b, 1]

    def getButton(self, id, color):
        return Button(id = str(id),
                      on_press = self.checker,
                      size_hint = self.sizeHint,
                      background_color = color)

    def updateTimer(self, dt):
        if not self.end:
            if time.time() - self.currentTime >= 1:
                self.currentTime = time.time()
                self.time -= 1

            self.label.text = 'Score: ' + str(self.score) + ' Time - ' + str(self.time) + ' sec.'
            if self.time <= 0:
                self.gameOver()

    def gameOver(self):
        self.end = True
        self.label.text = 'Game Over your score: <<< ' + str(self.score) + ' >>> - Press to play again'
        self.luckyNumber = randint(0, 3)
        self.sizeHint = (.5, .45)
        self.alpha = .2
        self.time = 16
        self.score = 0
        self.cell = 2

    def restart(self, instance):
        if self.end:
            # Delete old buttons
            for i in self.btnList:
                self.layout.remove_widget(i)
            self.btnList = []

            self.end = False
            self.addSetOfButton()
开发者ID:GitHubPyhon,项目名称:Game,代码行数:102,代码来源:eye_test.py

示例3: Peta

# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import remove_widget [as 别名]

#.........这里部分代码省略.........
        )
        self.bLayout.add_widget(self.jaringanJalanButton)
        self.bLayout.add_widget(self.jaringanAirBersihButton)
        self.bLayout.add_widget(self.jaringanGegorongButton)
        self.bLayout.add_widget(self.saranaPublik)
        self.bLayout.add_widget(self.zoomInButton)
        self.bLayout.add_widget(self.zoomOutButton)

        ## LEGEND CONTAINER ##
        self.legendContainer = StackLayout(
            orientation="lr-tb",
            size_hint=(None, None),
            minimum_width=366,
            minimum_height=672,
            width=366,
            height=105,
            pos_hint={"x": 0.75, "y": 0.70},
        )
        self.legendContainer.add_widget(self.legendBatasWil)

        self.mapScreen = MapLayout()

        # self.add_widget(self.mapScreen)
        self.add_widget(self.mapScreen.mapBound)
        self.add_widget(self.bLayout)
        self.add_widget(self.Navigation)
        self.add_widget(self.legendContainer)
        self.zoomIdx = 0

    ## Filter Button function method ##
    def jalan(self, b, **kwargs):
        if b.state == "down":
            self.mapScreen.addJalan()
            self.legendContainer.add_widget(self.legendJalan)

            # log
            gv.logger.log_button("view :" + "jalan")
        elif b.state == "normal":
            self.mapScreen.removeJalan()
            self.legendContainer.remove_widget(self.legendJalan)

            # log
            gv.logger.log_button("close :" + "jalan")

    def air(self, b, **kwargs):
        if b.state == "down":
            self.mapScreen.addAir()
            self.legendContainer.add_widget(self.legendAir)

            # log
            gv.logger.log_button("view :" + "air bersih")
        elif b.state == "normal":
            self.mapScreen.removeAir()
            self.legendContainer.remove_widget(self.legendAir)

            # log
            gv.logger.log_button("close :" + "air bersih")

    def gorong(self, b, **kwargs):
        if b.state == "down":
            self.mapScreen.addGorong()
            self.legendContainer.add_widget(self.legendGorong)

            # log
            gv.logger.log_button("view :" + "gorong-gorong")
        elif b.state == "normal":
            self.mapScreen.removeGorong()
            self.legendContainer.remove_widget(self.legendGorong)

            # log
            gv.logger.log_button("close :" + "gorong-gorong")

    def sarana(self, b, **kwargs):
        if b.state == "down":
            self.mapScreen.addSarana()
            self.legendContainer.add_widget(self.legendSarana)

            # log
            gv.logger.log_button("view :" + "sarana")
        elif b.state == "normal":
            self.mapScreen.removeSarana()
            self.legendContainer.remove_widget(self.legendSarana)

            # log
            gv.logger.log_button("close :" + "sarana")

    def reset(self):
        self.mapScreen.resetMap()
        self.legendContainer.clear_widgets()
        self.legendContainer.add_widget(self.legendBatasWil)
        self.jaringanJalanButton.state = "normal"
        self.jaringanAirBersihButton.state = "normal"
        self.jaringanGegorongButton.state = "normal"
        self.saranaPublik.state = "normal"

    def zoomIn(self, button=None, **args):
        self.mapScreen.zoomingIn()

    def zoomOut(self, button=None, **args):
        self.mapScreen.zoomingOut()
开发者ID:elianalien,项目名称:SadangSerangInformationCenter,代码行数:104,代码来源:peta.py


注:本文中的kivy.uix.stacklayout.StackLayout.remove_widget方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。