how can i create the label when ever i select the spinner value i.e Official and when ever i select spinner value normal hide the label?

BollamReddy :

[Here i have pasted my Code in GitHub Kindly Look Into it] { https://github.com/BollamReddy-Python-Vba/python/commit/710bd80f649968cd19181e0abda21f5164e8ba9f}

import kivy
kivy.require('1.10.0')
from kivy.core.window import Window
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.base import runTouchApp
from kivy.uix.label import Label
from kivy.graphics import Color, Rectangle
from kivy.uix.textinput import TextInput
from kivy.uix.spinner import Spinner
from kivy.uix.checkbox import CheckBox
Window.size = (500, 400)
Window.clearcolor = (0.1, 0.1, 0.3, 0.2)


def show_selected_value(spinner, text):
    print('Selected Process', spinner, 'have text', text)


class LRefConfigAutomation(App):
    config = None

    def build_config(self, config):
        config.setdefaults('LefConfigWindowSection', {
            'PartInputLabel': 'Please Enter your Part No',
            'TypeOfProcessLabel': 'Select Type Of Process',
            'NormalFolderName': 'Enter Normal Folder Name',

        })
        self.config = config

    def build(self):
        config = self.config
        root = FloatLayout()
        lbl = config.get('LefConfigWindowSection', 'PartInputLabel')
        self.label = Label(text=lbl, pos_hint={"center_x": .66, "center_y": .90}, size_hint=(1.0, 1.0), halign="left",valign="middle", font_name='Georgia')
        self.label.bind(size=self.label.setter('text_size'))
        self.label.font_size = '14.5dp'  # something that'll give texture bigger than phone's screen size
        root.add_widget(self.label)
        with self.label.canvas:
            Color(0, 0, 0, 0)
            Rectangle(pos=self.label.pos, size=self.label.size)
        self.txtKemNo = TextInput(pos_hint={"center_x": .66, "center_y": .90}, size_hint=(None, None),font_name="Georgia", size=(100, 30), multiline=False, hint_text="Part Number")
        root.add_widget(self.txtKemNo)
        lbl = config.get('LefConfigWindowSection', 'TypeOfProcessLabel')
        self.label = Label(text=lbl, pos_hint={"center_x": .66, "center_y": .75}, size_hint=(1.0, 1.0), halign="left",valign="middle", font_name='Georgia')
        self.label.bind(size=self.label.setter('text_size'))
        self.label.font_size = '14.5dp'  # something that'll give texture bigger than phone's screen size
        root.add_widget(self.label)
        with self.label.canvas:
            Color(0, 0, 0, 0)
            Rectangle(pos=self.label.pos, size=self.label.size)
        self.requestsspinner = Spinner(
            # default value shown
            text='Select Process',
            # available values will be binded to the combo
            values=("Normal", "Official"),
            # just for positioning in our example
            size_hint=(None, None),
            size=(110, 20),
            pos_hint={'center_x': .66, 'center_y': .75}, font_name='Georgia')
        self.requestsspinner.font_size = '14.5dp'
        self.requestsspinner.bind(text=show_selected_value)
        self.requestsspinner.bind(on_click=self.CreateLable)
        root.add_widget(self.requestsspinner)
        runTouchApp(root)
    def CreateLable(self, spinner, text):
        root = FloatLayout()
        print(text)
        if text == "Normal":
            pass
        elif text == "Official":
            config = self.config
            lbl = config.get('LefConfigWindowSection', 'NormalFolderName')
            print(lbl)
            self.label = Label(text=lbl, pos_hint={"center_x": .66, "center_y": .65}, size_hint=(1.0, 1.0),halign="left",valign="middle", font_name='Georgia')
            self.label.bind(size=self.label.setter('text_size'))
            self.label.font_size = '14.5dp'
            root.add_widget(self.label)
            with self.label.canvas:
                Color(0, 0, 0, 0)
                Rectangle(pos=self.label.pos, size=self.label.size)

if __name__ == "__main__":
    LRefConfigAutomation().run()
John Anderson :

There are three problems. First, your build() method is not returning the root (which is what it is intended to do). Remove the line:

runTouchApp(root)

and replace it with:

return root

Second, your CreateLable() is not being called. I suggest changing:

    self.requestsspinner.bind(on_click=self.CreateLable)

to:

    self.requestsspinner.bind(text=self.CreateLable)

The third problem is that in CreateLable() you are not adding the new Label to the display. The root that you create in that method has no relation to the root of your display. I suggest changing that method to:

def CreateLable(self, spinner, text):
    if text == "Normal":
        pass
    elif text == "Official":
        config = self.config
        lbl = config.get('LefConfigWindowSection', 'NormalFolderName')
        self.label = Label(text=lbl, pos_hint={"center_x": .66, "center_y": .65}, size_hint=(1.0, 1.0),halign="left",valign="middle", font_name='Georgia')
        self.label.bind(size=self.label.setter('text_size'))
        self.label.font_size = '14.5dp'
        self.root.add_widget(self.label)  # add label to the GUI
        with self.label.canvas:
            Color(0, 0, 0, 0)
            Rectangle(pos=self.label.pos, size=self.label.size)

You might want to delete the canvas instructions at the end of the above method. It is creating an invisible Rectangle at the bottom left od your display. The pos and size of the new Label are still at the default values of (0,0) and (100,100) at that point, so that is where the Rectangle is drawn, and where it will stay.

Here is the entire code:

import kivy
kivy.require('1.10.0')
from kivy.core.window import Window
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.graphics import Color, Rectangle
from kivy.uix.textinput import TextInput
from kivy.uix.spinner import Spinner
Window.size = (500, 400)
Window.clearcolor = (0.1, 0.1, 0.3, 0.2)


def show_selected_value(spinner, text):
    print('Selected Process', spinner, 'have text', text)


class LRefConfigAutomation(App):
    config = None

    def build_config(self, config):
        config.setdefaults('LefConfigWindowSection', {
            'PartInputLabel': 'Please Enter your Part No',
            'TypeOfProcessLabel': 'Select Type Of Process',
            'NormalFolderName': 'Enter Normal Folder Name',

        })
        self.config = config

    def build(self):
        config = self.config
        root = FloatLayout()
        lbl = config.get('LefConfigWindowSection', 'PartInputLabel')
        self.label = Label(text=lbl, pos_hint={"center_x": .66, "center_y": .90}, size_hint=(1.0, 1.0), halign="left",valign="middle", font_name='Georgia')
        self.label.bind(size=self.label.setter('text_size'))
        self.label.font_size = '14.5dp'  # something that'll give texture bigger than phone's screen size
        root.add_widget(self.label)
        with self.label.canvas:
            Color(0, 0, 0, 0)
            Rectangle(pos=self.label.pos, size=self.label.size)
        self.txtKemNo = TextInput(pos_hint={"center_x": .66, "center_y": .90}, size_hint=(None, None),font_name="Georgia", size=(100, 30), multiline=False, hint_text="Part Number")
        root.add_widget(self.txtKemNo)
        lbl = config.get('LefConfigWindowSection', 'TypeOfProcessLabel')
        self.label = Label(text=lbl, pos_hint={"center_x": .66, "center_y": .75}, size_hint=(1.0, 1.0), halign="left",valign="middle", font_name='Georgia')
        self.label.bind(size=self.label.setter('text_size'))
        self.label.font_size = '14.5dp'  # something that'll give texture bigger than phone's screen size
        root.add_widget(self.label)
        with self.label.canvas:
            Color(0, 0, 0, 0)
            Rectangle(pos=self.label.pos, size=self.label.size)
        self.requestsspinner = Spinner(
            # default value shown
            text='Select Process',
            # available values will be binded to the combo
            values=("Normal", "Official"),
            # just for positioning in our example
            size_hint=(None, None),
            size=(110, 20),
            pos_hint={'center_x': .66, 'center_y': .75}, font_name='Georgia')
        self.requestsspinner.font_size = '14.5dp'
        self.requestsspinner.bind(text=show_selected_value)
        self.requestsspinner.bind(text=self.CreateLable)
        root.add_widget(self.requestsspinner)
        return root

    def CreateLable(self, spinner, text):
        if text == "Normal":
            pass
        elif text == "Official":
            config = self.config
            lbl = config.get('LefConfigWindowSection', 'NormalFolderName')
            self.label = Label(text=lbl, pos_hint={"center_x": .66, "center_y": .65}, size_hint=(1.0, 1.0),halign="left",valign="middle", font_name='Georgia')
            self.label.bind(size=self.label.setter('text_size'))
            self.label.font_size = '14.5dp'
            self.root.add_widget(self.label)

if __name__ == "__main__":
    LRefConfigAutomation().run()

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=398101&siteId=1