Skip to content
Advertisement

Kivy Label is not showing up

So I am a beginner in kivy. I have written a programm that reads sentences from a list and displays them in a Boxlayout as buttons. The Boxlayout is in a Floatlayout, so I can control where the sentences are located. If I click one of the sentences, it splits into buttons for each word. So far so good. Now I want to create a Label, that shows up somewhere below the Boxlayout. It should show up whenever a word button is clicked, and display the same text as the button. So lets say I have this sentence as a Button:

| Hello World, this is an example sentence. |

If I click the sentence:

| Hello || World || this || is || an || example || sentence |

The words should split into indivudal buttons. When I click for example the ‘sentence’ Button, a Label should show up somewhere below having the text ‘sentence’

.py:

JavaScript

Advertisement

Answer

The problem is that you are actually adding a label into another label in your function show but you never accessed the label you’ve already added to the app’s subclass.

The fixes are as follows,

  1. First create a reference for that label,
JavaScript
  1. Pass exactly the ‘word’ in method destroy_then_create as before using kwarg.,
JavaScript
  1. Now make the following changes in function show,
JavaScript

You could’ve added this function show anywhere in your code but remember to access the app instance in whatever way is suitable.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement