0
votes
  1. {Actually whenever i click on the spinner value (official) label is created,at that time i click on the another spinner value "Normal" created label is hiding. this scenario working fine, But Coming To my 2nd scenario -- whenever i click on the spinner value (Normal) first time,it showing an error}

    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.label01 = 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.label01.bind(size=self.label01.setter('text_size'))
        self.label01.font_size = '14.5dp'  # something that'll give texture bigger than phone's screen size
        root.add_widget(self.label01)
        with self.label01.canvas:
            Color(0, 0, 0, 0)
            Rectangle(pos=self.label01.pos, size=self.label01.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.label02 = 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.label02.bind(size=self.label02.setter('text_size'))
        self.label02.font_size = '14.5dp'  # something that'll give texture bigger than phone's screen size
        root.add_widget(self.label02)
        with self.label02.canvas:
            Color(0, 0, 0, 0)
            Rectangle(pos=self.label02.pos, size=self.label02.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):
        config = self.config
        if text == "Official":
            lbl = config.get('LefConfigWindowSection', 'NormalFolderName')
            self.label03 = 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.label03.bind(size=self.label03.setter('text_size'))
            self.label03.font_size = '14.5dp'
            self.root.add_widget(self.label03)
            with self.label03.canvas:
                Color(0, 0, 0, 0)
                Rectangle(pos=self.label03.pos, size=self.label03.size)
        elif text == "Normal":
            self.label03.text = ""
    

    if name == "main": LRefConfigAutomation().run()

enter image description here

1
Can you add your Error?JustLearnedIt
i have added the error imageBollamReddy
Can you please also make a minimal, reproducible Example and then format your code as code?JustLearnedIt
actually i'm unable to do that one ,i'm getting lot of errors ,could you please help meBollamReddy
github.com/BollamReddy-Python-Vba/python/blob/master/TestData --- I have pasted my code in GitHub, Kindly look into itBollamReddy

1 Answers

0
votes

In CreateLabel, you need to move the creation part outside of the if condition: So this part

lbl = config.get('LefConfigWindowSection', 'NormalFolderName')
        self.label03 = 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.label03.bind(size=self.label03.setter('text_size'))
        self.label03.font_size = '14.5dp'
        self.root.add_widget(self.label03)

should be before if text == "Official":. Otherwise, you get an error because you haven't created self.label03. Complete CreateLabel:

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

There's another problem in CreateLabel:

self.label03 = Label(...)

Everytime you call CreateLabel, self.label03 is assigned a new Label, not the first one. So instead of hiding the first one you're creating a new one and hiding this. There are multiple ways to solve but here's one:

def build(self):
    ... # add these two lines to create the Label once
    self.CreateLabel()  
    root.add_widget(self.label03)
    # Use another function (UpdateLabel) to update the value
    self.requestsspinner.bind(text=show_selected_value)
    self.requestsspinner.bind(text=self.UpdateLable)
    ...

# Only called once to create the Label
def CreateLabel(self):
    self.label03 = Label(text="", pos_hint={"center_x": .66, "center_y": .65}, size_hint=(1.0, 1.0),
                             halign="left", valign="middle")
    self.label03.bind(size=self.label03.setter('text_size'))
    self.label03.font_size = '14.5dp' 
    with self.label03.canvas:
        Color(0, 0, 0, 0)
        Rectangle(pos=self.label03.pos, size=self.label03.size)

# Changes the Label 
def UpdateLable(self, spinner, text):        
    if text == "Official":
        config = self.config
        self.label03.text =  config.get('LefConfigWindowSection', 'NormalFolderName')            
    elif text == "Normal":
        self.label03.text = ""