Skip to content
Advertisement

how I will Change the font size of the text of kivy button dynamically in .py file

Actually I want to try to Change my kivy Button’s font_Size dynamically Accoding to the Width of its Parnet Widget. so I can make it resizable according to the Screen of Kivy Gui App I am want to Change it in .py file as a code (without the use of .kv file or kv string) I am using some kind of trick which is well working on .kv file or kv string but it does not working in the .py file, and that trick is I equal the font_size of button text to the (width/6) [font_size=another_widget.width/6] of the parent widget but there is not effect it does not get change dynamically and it will fixed the font_size only. I want to change the Button font size which is referred by main_text and Hint_text varaibles in the Source Code the line no. 36 and 46 respectively for these variables in the code The whole Source code is here:-

JavaScript

So I want the Solution that is by which trick or method can i able to change the font_size of the text of buttons dynamically. if yes so please let me know also. it will be very helpful for me. Thank You!!

Advertisement

Answer

It works in kv because kv automatically sets up bindings to adjust properties that depend on other properties. But if you are not using kv, you must set up those bindings yourself. Without those bindings, the font_size values will be set based on the width of mycard at the time that the main_text and Hint_text Buttons are created, and will not be updated. Here is a modified version of your FirstWin class that does the bindings:

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