Skip to first unread message

Parth Bissa

unread,
May 6, 2020, 6:08:35 AM5/6/20
to Kivy users support
I am building an app using kivy in which there are a bunch of buttons , labels and screens. My App is running fine inside PC and my personal android phone which i used for testing that app but when i use the app on other android phones having different display size ,the text does not resizes itself. So please help me what to use so that the text resizes according to display size.

Aakanksha Smriti

unread,
May 6, 2020, 9:50:49 AM5/6/20
to kivy-...@googlegroups.com
I'm also facing a similar issue.

On Wed, 6 May 2020 at 06:08, Parth Bissa <parth...@gmail.com> wrote:
I am building an app using kivy in which there are a bunch of buttons , labels and screens. My App is running fine inside PC and my personal android phone which i used for testing that app but when i use the app on other android phones having different display size ,the text does not resizes itself. So please help me what to use so that the text resizes according to display size.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/6a11d660-1479-43fe-952a-4d7207a0ebbd%40googlegroups.com.

Parth Bissa

unread,
May 6, 2020, 10:11:06 AM5/6/20
to Kivy users support
Did You Got Any Solution to this?? As I have searched a lot but found nothing useful


On Wednesday, May 6, 2020 at 7:20:49 PM UTC+5:30, asmriti wrote:
I'm also facing a similar issue.

On Wed, 6 May 2020 at 06:08, Parth Bissa <parth...@gmail.com> wrote:
I am building an app using kivy in which there are a bunch of buttons , labels and screens. My App is running fine inside PC and my personal android phone which i used for testing that app but when i use the app on other android phones having different display size ,the text does not resizes itself. So please help me what to use so that the text resizes according to display size.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Sandeep Jadam

unread,
May 6, 2020, 10:38:14 AM5/6/20
to kivy-...@googlegroups.com
#try this ;)
from kivy.config import Config
Config.set('graphics', 'width', '360')
Config.set('graphics', 'height', '740')

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/b705cefb-aac6-4e4d-bfef-b85235f8fee8%40googlegroups.com.

Elliot Garbus

unread,
May 6, 2020, 4:32:46 PM5/6/20
to kivy-...@googlegroups.com

The first thing to ensure you are doing is using the metrics module to specify the sizes in a way that should automatically adjust per platform.

For fonts this is sp().  You can express this syntax in 2 ways:

 

font_size: sp(20)

OR

font_size: ‘20sp’

 

read: https://kivy.org/doc/stable/api-kivy.metrics.html?highlight=sp#dimensions

 

If you are already using sp() or if this approach is not sufficient for your use case, there are a number of ways to scale the font size. 

Let me know.

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

Message has been deleted

Parth Bissa

unread,
May 8, 2020, 7:46:16 AM5/8/20
to Kivy users support
I used sp() but it didn't change according to display 
 

On Thursday, May 7, 2020 at 2:02:46 AM UTC+5:30, Elliot Garbus wrote:

The first thing to ensure you are doing is using the metrics module to specify the sizes in a way that should automatically adjust per platform.

For fonts this is sp().  You can express this syntax in 2 ways:

 

font_size: sp(20)

OR

font_size: ‘20sp’

 

read: https://kivy.org/doc/stable/api-kivy.metrics.html?highlight=sp#dimensions

 

If you are already using sp() or if this approach is not sufficient for your use case, there are a number of ways to scale the font size. 

Let me know.

 

 

From: Parth Bissa
Sent: Wednesday, May 6, 2020 3:08 AM
To: Kivy users support
Subject: [kivy-users] Screen Size Issue in Kivy App

 

I am building an app using kivy in which there are a bunch of buttons , labels and screens. My App is running fine inside PC and my personal android phone which i used for testing that app but when i use the app on other android phones having different display size ,the text does not resizes itself. So please help me what to use so that the text resizes according to display size.

 

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Elliot Garbus

unread,
May 8, 2020, 12:16:28 PM5/8/20
to kivy-...@googlegroups.com

I started to put a little experiment together to change the text size dynamically.  I don’t have the time to finish it right now – but thought it might inspire you.

 

When the size of the button changes, the code compares the size of the text (texture_size) to the size of the widget and then adjusts.  Current it is only checking for height.  Ultimately it will test for height and width and get a best fit.

 

 

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.button import Button

kv =
"""
BoxLayout:
    orientation: 'vertical'
    ScaleButton:
        text: 'Test One'
    ScaleButton:
        text: 'This is a test of a much longer string of text'
    ScaleButton:
        text: 'Yet another string'
"""


class ScaleButton(Button):
   
def on_size(self, *args):
       
print('size changed')
        tw,th =
self.texture_size
        width,height =
self.size
       
if height < width:  # Grow or shrink height
           
if th < height: # Grow
               
while(th < height):
                   
self.font_size += 1
                   
self.texture_update()
                    th =
self.texture_size[1]
           
else: # shrink
                
while (th > height):
                   
self.font_size -= 1
                   
self.texture_update()
                    th =
self.texture_size[1]



class ScaleFontApp(App):
   
def build(self):
       
return Builder.load_string(kv)


ScaleFontApp().run()

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/242c00ff-69fa-4904-98c0-1c04a4fc3352%40googlegroups.com.

 

Elliot Garbus

unread,
May 8, 2020, 9:03:23 PM5/8/20
to Kivy users support
Now this little app will scale the text to fit the button based on height or width.

I suspect that you could do something much simpler for your app.  Across the range of device sizes you support I guess you use 2 to 4 different font sizes on for each device size.  If this is the case you could test the height and width, and select the desired font_size.  If you redefine the font_size in label, It will change the fonts size across your app (unless it is being defined in other widgets.

App that scales font based on the size of a button:

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.button import Button

kv = """
BoxLayout:
orientation: 'vertical'
ScaleButton:
text: 'Test One'
ScaleButton:
text: 'This is a test of a much longer string of text'
ScaleButton:
text: 'Yet another string'
"""


class ScaleButton(Button):
def on_size(self, *args):
        t_width,t_height= self.texture_size
width,height = self.size
if t_height < height and t_width < width: # Grow
while t_height < height and t_width < width:
self.font_size += 1
self.texture_update()
t_width,t_height= self.texture_size
elif t_height > height or t_width > width: # shrink
while t_height > height or t_width > width:
self.font_size -= 1
self.texture_update()
t_width,t_height= self.texture_size



class ScaleFontApp(App):
def build(self):
return Builder.load_string(kv)


ScaleFontApp().run()

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+unsubscribe@googlegroups.com.

Message has been deleted

Parth Bissa

unread,
May 9, 2020, 7:44:20 AM5/9/20
to Kivy users support
After Reading this i think you have almost solved my problem but i need help on these :

Reducing font_size in your code makes the program stuck on a white screen 

Also I want to tell that I am adding Labels as result on a button press so I need some mechanism like this one which will help in placement of labels.
If there will be a label or button existing at a position then label will not be placed there and vice versa.
Also I can use this existing code which you have to estimate size of label.

Parth Bissa

unread,
May 9, 2020, 8:03:18 AM5/9/20
to Kivy users support
I am placing those labels as :

self.add_widget(Label(text = "blahblahblah")
self.add_widget(Label(text = "blahblahblah")
self.add_widget(Label(text = "blahblahblah")

And the problem is that i want self postioning of labels according to empty space on screen. Talking about size of Label ,I think the above code has solved the problem of size because the same code can be used for labels also.

Thanking You In Advance......

Elliot Garbus

unread,
May 9, 2020, 9:55:59 AM5/9/20
to kivy-...@googlegroups.com

If you want the labels automatically sized to the position on the screen, use a layout.

Here is a small example using a vertical BoxLayout.

 

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout

kv =
"""
RootBoxLayout:
    orientation: 'vertical'
    BoxLayout:
        orientation: 'vertical'
        id: label_space
    BoxLayout:
        size_hint_y: None
        height: 48
        Button:
            text: 'Add Label'
            on_release: root.add_size_label()
        Button:
            text: 'Reset'
            on_release: root.remove_labels()
        
"""


class SizeLabel(Label):
   
def on_size(self, *args):
        t_width,t_height=
self.texture_size
        width,height =
self.size
       
if t_height < height and t_width < width: # Grow
           
while t_height < height and t_width < width:
               
self.font_size += 1
               
self.texture_update()
                t_width,t_height=
self.texture_size
       
elif t_height > height or t_width > width: # shrink
           
while t_height > height  or t_width > width:
                
self.font_size -= 1
               
self.texture_update()
                t_width,t_height=
self.texture_size


class RootBoxLayout(BoxLayout):
   
def add_size_label(self):
        w = SizeLabel(
text='bla-bla-bla')
       
self.ids.label_space.add_widget(w)

   
def remove_labels(self):
        child_widgets =
self.ids.label_space.children.copy()
       
for child in child_widgets:
           
self.ids.label_space.remove_widget(child)


class SizeLabelApp(App):
   
def build(self):
       
return Builder.load_string(kv)


SizeLabelApp().run()

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/3517ee49-e34d-47ff-9382-60b8811f56fb%40googlegroups.com.

 

Parth Bissa

unread,
May 10, 2020, 7:21:52 AM5/10/20
to Kivy users support
Thanks Again For Helping With the Code But My Code Is little different than yours Have A Look :

kv ''' <MENU> : 

Button : 
text : 'bbbbbb'
on_press : root.get_result()

''''

def get_result(self):

self.add_widget(Label(text = "sdalsdkj"+str(y))
self.add_widget(Label(text = "ssdwrj"+str(z))
self.add_widget(Label(text="dsad" + str(x))




So this how i am showing results and i want all these labels to be placed so that they do not overlap with each other or other label and buttons. And For the Sizing of label i think your code is enough.














Elliot Garbus

unread,
May 10, 2020, 10:29:20 AM5/10/20
to kivy-...@googlegroups.com

Post a runnable example.  There is not enough here for me to help.

Is menu a screen?  Is self a screen?

 

How do you want the Labels to layout?

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/ce1f93ea-a8bf-4b85-8d9e-fc8fe80fd272%40googlegroups.com.

 

Parth Bissa

unread,
May 11, 2020, 4:15:20 AM5/11/20
to Kivy users support
Sorry For that.Here is my code : 
Look Here When I am in IndiaResult Screen I Press Get Result Button And it produces result in form of three labels. But These Labels are overlapping each other and i dont know how to position them so that they do not overlap as well as change their size according to screen.


KV FILE : : 
<IndiaResult>
GridLayout:
rows : 10


ScaleButton :
text : "[b][color=#ff9900]GET[/color][color=#ffffff] RES[/color][color=#00cc00]ULTS[/color][/b] "
markup : True
background_color: (0.0, 0.0, 1.0,0.7)
on_press : root.india()
ScaleButton :
text : "[b][color=#ff9900]BACK[/color][color=#ffffff] TO[/color][color=#00cc00] MENU[/color][/b]"
markup : True
background_color: (0.0, 0.0, 1.0,0.7)
on_press : root.manager.current = 'menu'

Label :
text : ""
size_hint : 5,5


Python File : :
class IndiaResult(Screen):

def india(self):

try:

url = "https://covid-19-india-data-by-zt.p.rapidapi.com/GetIndiaTotalCounts"

headers = {
'x-rapidapi-host': "covid-19-india-data-by-zt.p.rapidapi.com",
'x-rapidapi-key': "3ae1125923msha231c2e1fc6c41ep14814cjsnfe458e46c62f"
}
time.sleep(1)
response = requests.request("GET", url, headers=headers)
x = response.text
parsed = json.loads(x)
g = parsed['data']
print(parsed)
CONFIRMED = g[0]['confirmed']
RECOVERED = g[0]['recovered']
DEATHS = g[0]['deaths']

print("CONFIRMED :" + CONFIRMED)
print("RECOVERED :" + RECOVERED)
print("DEATHS :" + DEATHS)



self.add_widget(ScLabel(text="[b][color=#FFFF00]TOTAL CONFIRMED : [/color][/b]" + str(CONFIRMED), markup=True))
self.add_widget(ScLabel(text="[b][color=#33FF7C]TOTAL RECOVERED : [/color][/b]"+ str(RECOVERED), markup=True))
self.add_widget(ScLabel(text="[b][color=#FF0000]TOTAL DEATHS : [/color][/b]"+ str(DEATHS), markup=True))










Elliot Garbus

unread,
May 11, 2020, 9:02:57 AM5/11/20
to kivy-...@googlegroups.com

Currently you are adding the Labels to the screen, but not to the Layout.  A Screen is a RelativeLayout, the Labels do not have position hints so they are overalaping.

Assuming you want to add the Labels to the GridLayout make the following changes:

 

  1. Add an id to the GridLayout in the kv code:

 

<IndiaResult>
    GridLayout:
        rows : 10

        Id: grid

(The rest of the kv code stays the same)

 

  1. Add the Labels to the FridLayout, using the id.  In the Python code:

 

self.ids.grid.add_widget(ScLabel(text="[b][color=#FFFF00]TOTAL CONFIRMED :  [/color][/b]" + str(CONFIRMED), markup=True))
self.ids.grid.add_widget(ScLabel(text="[b][color=#33FF7C]TOTAL RECOVERED : [/color][/b]"+ str(RECOVERED)markup=True))
self.ids.grid.add_widget(ScLabel(text="[b][color=#FF0000]TOTAL DEATHS : [/color][/b]"+ str(DEATHS), markup=True))

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/36bf5eab-a37a-4790-95a1-d773b5a13bc4%40googlegroups.com.

 

Message has been deleted

Parth Bissa

unread,
May 12, 2020, 6:20:57 AM5/12/20
to Kivy users support
Thanks It Worked Absolutely Fine On Both PC And Mobile But the Screen Loading is taking more time any tip using which i can make it fast....

Elliot Garbus

unread,
May 12, 2020, 10:58:32 AM5/12/20
to kivy-...@googlegroups.com

Id and ids are described here: https://kivy.org/doc/stable/api-kivy.lang.html?highlight=lang#ids

 

In short, when a kv file is parsed, the id in each widget goes into and ids dictionary.  The key is the id, the value is the widget object.  The root widget and each rule has an ids dict.  Using the ids is a key part of navigating kivy.  It provides a mechanism to access any widget from any class or location.

 

From: Parth Bissa
Sent: Tuesday, May 12, 2020 2:23 AM
To: Kivy users support
Subject: Re: [kivy-users] Screen Size Issue in Kivy App

 

Thank You So Much It Worked..................

 

What is this id btw never seen it in any kivy code?

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

Parth Bissa

unread,
May 13, 2020, 8:54:13 AM5/13/20
to Kivy users support
Thank You For Explaining....

I noticed that the code by which font size is calculated is taking time which is making the UI slow and hence loss in app performance so is there any way to fix.... Or Add a loading sign or animation.......

Elliot Garbus

unread,
May 13, 2020, 9:28:04 AM5/13/20
to kivy-...@googlegroups.com

You could try a few things to simplify the scaling code.

  • It currently increases the fort size by 1 each iteration, seeking the best fit.  Increasing from 1 to 5 or 10 will dramatically reduce the number of iterations.
  • Rather than dynamically scaling to fit, you could set a font size based on screen dimensions.

 

I put together an example that loads screens one at a time with a progress bar.

https://groups.google.com/d/msg/kivy-users/1ROv9VHTbaw/PiLoKQyhHAAJ

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/6ca527fe-bd82-47df-bb33-445ce8399ed6%40googlegroups.com.

 

Parth Bissa

unread,
May 26, 2020, 6:39:56 AM5/26/20
to Kivy users support
Font Size is Increasing without any problem but it is not reducing. Program just stucks with a white screen and doesnt respond. Please Help

Elliot Garbus

unread,
May 26, 2020, 11:01:13 AM5/26/20
to kivy-...@googlegroups.com

Share your code.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/33c7cd85-6683-4d56-9164-921188e43a24%40googlegroups.com.

 

Parth Bissa

unread,
May 27, 2020, 6:11:49 AM5/27/20
to Kivy users support
The Code you gave : : 


class ScaleButton(Button):
def on_size(self, *args):
t_width, t_height = self.texture_size
        width, height = self.size

if t_height < height and t_width < width: # Grow
while t_height < height and t_width < width:
self.font_size += 1
self.texture_update()
t_width, t_height = self.texture_size

        elif t_height > height and t_width > width: # shrink
            while t_height > height  and t_width > width:
                self.font_size -= 20
self.texture_update()
t_width,t_height= self.texture_size

KV FILE : : 


<IndiaResult>
GridLayout:
rows : 10


ScaleButton :
text : "[b][color=#ff9900]GET[/color][color=#ffffff] RES[/color][color=#00cc00]ULTS[/color][/b] "
markup : True
background_color: (0.0, 0.0, 1.0,0.7)
on_press : root.india()
ScaleButton :
text : "[b][color=#ff9900]BACK[/color][color=#ffffff] TO[/color][color=#00cc00] MENU[/color][/b]"
markup : True
background_color: (0.0, 0.0, 1.0,0.7)
on_press : root.manager.current = 'menu'

Label :
text : ""
size_hint : 5,5



Python Code : : 

class IndiaResult(Screen):
def india(self):

try:
url = "https://covid-19-india-data-by-zt.p.rapidapi.com/GetIndiaTotalCounts"

headers = {
'x-rapidapi-host': "covid-19-india-data-by-zt.p.rapidapi.com",
'x-rapidapi-key': "3ae1125923msha231c2e1fc6c41ep14814cjsnfe458e46c62f"
}
time.sleep(1)
response = requests.request("GET", url, headers=headers)
x = response.text
parsed = json.loads(x)
g = parsed['data']
print(parsed)
CONFIRMED = g[0]['confirmed']
RECOVERED = g[0]['recovered']
DEATHS = g[0]['deaths']

print("CONFIRMED :" + CONFIRMED)
print("RECOVERED :" + RECOVERED)
print("DEATHS :" + DEATHS)

            self.ids.grid.add_widget(

ScLabel(text="[b][color=#FFFF00]TOTAL CONFIRMED : [/color][/b]" + str(CONFIRMED), markup=True))
self.ids.grid.add_widget(
ScLabel(text="[b][color=#33FF7C]TOTAL RECOVERED : [/color][/b]" + str(RECOVERED), markup=True))
self.ids.grid.add_widget(
ScLabel(text="[b][color=#FF0000]TOTAL DEATHS : [/color][/b]" + str(DEATHS), markup=True))


        except requests.exceptions.ConnectionError :
def show_popup():
self.ids.grid.add_widget(ScLabel(text = "[b]KINDLY CHEK YOUR NETWORK CONNECTION[/b]",markup=True))
show_popup()

except json.JSONDecodeError:
def show_popup():
self.ids.grid.add_widget(ScLabel(text="[b]KINDLY CHEK YOUR NETWORK CONNECTION[/b]",markup=True))
show_popup()

pass


This is my code!

Elliot Garbus

unread,
May 27, 2020, 10:50:51 AM5/27/20
to kivy-...@googlegroups.com

Please send a minimal runnable example.

There is something wrong here.  In the python code you are using the id ‘grid’, but I don’t see in in the KV code.

 

Your exception handlers are declaring and calling the same code.  The code is being declared in a nested way.  This is not necessary.  You are declaring the same function twice. Either elevate show_popup() to the same level as a method, or just use the have the single line of code you want to execute.  Is this a placehoder?

 

Also, make an asynchronous call and use the completion callback or event.  Do not use sleep.  Your app will appear dead and unresponsive during sleep.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/3d72f8a7-1d65-4a0f-84cf-661f318074a7%40googlegroups.com.

 

Elliot Garbus

unread,
May 27, 2020, 3:11:22 PM5/27/20
to kivy-...@googlegroups.com

I made an enhancement where the minimum text size can be set.  There was a possibility of getting into an endless loop If the font size went negative, that also has been fixed.

 

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.button import Button
from kivy.properties import NumericProperty

kv =
"""
<ScaleButton>:
    padding: 10,10

BoxLayout:
    orientation: 'vertical'
    Label:
        text: 'Test ScaleButton in a GridLayout'
        font_size: 20
        size_hint_y: .1
    GridLayout:
        id: grid
        rows: 10
"""


class ScaleButton(Button):
    min_font_size = NumericProperty(
5)

   
def on_size(self, *args):
        t_width,t_height=
self.texture_size
        width,height =
self.size
       
if t_height < height and t_width < width: # Grow
           
while t_height < height and t_width < width:
               
self.font_size += 1
               
self.texture_update()
                t_width,t_height=
self.texture_size
       
elif t_height > height or t_width > width: # shrink
           
while t_height > height  or t_width > width:
               
self.font_size = max(self.font_size - 1, self.min_font_size)
               
if self.font_size == self.min_font_size:
                   
break
               
self.texture_update()
                t_width,t_height=
self.texture_size


class ScaleFontApp(App):
   
def build(self):
       
return
Builder.load_string(kv)

   
def on_start(self):
       
for i in range(10):
            sb = ScaleButton(
text='This is Button '+str(i))
           
self.root.ids.grid.add_widget(sb)



ScaleFontApp().run()

Thank You For Explaining....

 

1.       Add an id to the GridLayout in the kv code:

 

<IndiaResult>
    GridLayout:
        rows : 10

        Id: grid

(The rest of the kv code stays the same)

 

2.       Add the Labels to the FridLayout, using the id.  In the Python code:

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/3d72f8a7-1d65-4a0f-84cf-661f318074a7%40googlegroups.com.

 

Parth Bissa

unread,
May 28, 2020, 12:21:54 PM5/28/20
to Kivy users support
Still Size is only Increasing Not reducing and also taking time to load screen due to loops

Thank You For Explaining....

 

self.ids.grid.add_widget(ScLabel(text="[b][color=#33FF7C]TOTAL RECOVERED : [/color][/b]"+ str(RECOVERED)markup<span style='font-family:Co

Parth Bissa

unread,
May 28, 2020, 12:25:33 PM5/28/20
to Kivy users support
Can you suggest what i should use to show an error?

Thank You For Explaining....

 

))
           
self<span style='font-family:Consolas;color:#A

Elliot Garbus

unread,
May 28, 2020, 12:26:09 PM5/28/20
to kivy-...@googlegroups.com

Run my code.  The font reduces in size and grows in size.  Share your code, I will take a look at it.

If you want to reduce the number of iterations, increase the font scaling increment.  In the example below it is 1, set it to 5 or 10.

 

In many ways this is overkill calculating a size for every instance.  You could do a calculation like this on one widget, and use it to calculate a font_size that you use everywhere.

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

Elliot Garbus

unread,
May 28, 2020, 12:43:06 PM5/28/20
to kivy-...@googlegroups.com

You can use: https://kivy.org/doc/stable/api-kivy.network.urlrequest.html?highlight=url#module-kivy.network.urlrequest

And use  callbacks for the error cases.  The kivy function does the JSON decoding.

 

If you want to use requests and exception handlers:

 

        except requests.exceptions.ConnectionError :
           self.show_popup()

       
except json.JSONDecodeError:
           self.show_popup()

def show_popup(self):

    self.ids.grid.add_widget(ScLabel(text="[b]KINDLY CHEK YOUR NETWORK CONNECTION[/b]",markup=True))

   

You might consider putting your try except where India is called, putting it as high up in the call stack as possible, will enable you to create better exception handling.

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

Parth Bissa

unread,
May 29, 2020, 5:50:46 AM5/29/20
to Kivy users support
Not Fully Understood Let me send the whole code to you!

Thank You For Explaining....

 

 

KV FILE : : 

   &nbsp

Parth Bissa

unread,
May 29, 2020, 5:57:50 AM5/29/20
to Kivy users support
This Code Worked Thank You Font Size Reduces And Also loading is taking less time. I forgot to add padding of button in kv file. 

Thank You For Explaining....

 

Parth Bissa

unread,
May 29, 2020, 6:08:51 AM5/29/20
to Kivy users support
Here are my files Kindly have a look and suggest where i need to improve. Thank You in Advance.
main.kv
main.py

Parth Bissa

unread,
May 29, 2020, 6:12:26 AM5/29/20
to Kivy users support
Also when i press get results two or more times the results are printed again and again and i couldnt find any alternative to remove after printing results once 

Elliot Garbus

unread,
May 29, 2020, 2:36:51 PM5/29/20
to kivy-...@googlegroups.com

Here are a few things to thing about.

You have almost the same code repeated many times.  This type of code is difficult to maintain and very error prone.  If you have a mistake, you need to fix it over, and over…  

 Without looking too closely it appears you have the same code, what changes is the index into a list.  Consider creating one method to read the data, and pass in the index.  Better yet create a dict that associates the name of the screen with the appropriate index.

 

Lots of your screens also all have the same structure.  You can create one screen class and instance it multiple times.  Customize it with the data that needs to be unique to each screen.

 

This will dramatically reduce the amount of code, and make it much more maintainable.  Your screenmanager might end up looking like:

 

ScreenManager:
   
id: scr_mngr
   
size_hint_y : None
   
height : root.height - toolbar.height
   
Welcome :
       
id:sc0
    DataScreen:
       
name: ‘Assam’
    DataScreen:
       
name: ‘Haryana


--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

Parth Bissa

unread,
May 30, 2020, 4:34:03 AM5/30/20
to Kivy users support
I am new here so i didn't know these things so thanks for your help I will try this and reply you here or if you give any mail or whatsapp number where i can take some tips that would be great

Elliot Garbus

unread,
May 30, 2020, 9:32:48 AM5/30/20
to kivy-...@googlegroups.com

Try to get a common DataScreen working for 2 locations.  After it is working, you can easily scale it out to all the locations you want to represent.

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

Parth Bissa

unread,
May 31, 2020, 6:40:05 AM5/31/20
to Kivy users support
how?

Elliot Garbus

unread,
May 31, 2020, 12:11:21 PM5/31/20
to kivy-...@googlegroups.com

The code attached is an example.   I stripped out a few things from your code.

All of the results come back with one URL request, so I only do one request, rather than a request per screen.

 

You were creating widgets in the gridlayout on each screen, each time you visited the screen, but never clearing them.  I allocated the labels in kv, and filled them from python.

 

happy to answer any questions.

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

main.zip

Parth Bissa

unread,
Jun 1, 2020, 7:46:19 AM6/1/20
to Kivy users support
Wow! so much line of code reduced but where will my navigation drawer go because i want materialistic theme and also my other screens (India Status and World Status). Apart from these what is the work of event dispatcher here?

Share your code.

 

<p class=MsoNormal style='mso-margin-top-alt:auto;ms

Elliot Garbus

unread,
Jun 1, 2020, 10:15:53 AM6/1/20
to kivy-...@googlegroups.com

I suspect you can put the rest of your widgets/design elements as you had them before.  I did not spend anytime looking at that part of the code.   I haven’t used KivyMD, so I kept it all in kivy for the example.

 

The EventDispatcher is not required for this code.  You can remove it, changing the class declaration to:

class CV19Data:

 

If you are going to use kivy properties, and no widgets, you would need to have a class derived from EventDispatcher.  I will often put the code returned from this kind of API call into a kivy property so screens update automatically, we can do that here as well, but I didn’t and its more in keeping with how you wrote the screen.    We could create a list of the attributes we want to display in  a list property, and put those kivy properties on the screen.  No real benefit over writing the value to the labels as you have done.

 

You could reduce the code even further by dynamically creating the screens in the ScreenManager, by looping over the locations dict.

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages