Tags down


Dynamic buttons with images with Kivy

By : user2174972
Date : October 16 2020, 08:10 PM
hope this fix your issue You can set the size of your Botao in your kv file as a function of the root.size. By using min(root.size). You must also remove the size: 138, 138 line.
code :
    font_size: 32
    color: 1, 1, 1, 1
    #size: 138, 138
    background_normal: 'bd.png'
    background_down: 'bd1.png'
    background_color: 0.88, 0.88, 0.88, 1  
    size_hint: None, None

        size: (min(root.size)*0.5, min(root.size)*0.5)
        pos_hint: {"center_x": .5, "center_y": .5}

Share : facebook icon twitter icon

KIVY : Image + Label inside dynamic buttons

By : Claire Vo Lawless
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , It's actually not displaying only for the last button - it's displaying for each button, but in the same position. The problem is that Button is not a layout, and as such, does not perform layout of its children. So the GridLayout for each button is rendered at 0, 0 with size 100, 100 relative to the origin of the nearest relative parent (in this case, the GridLayout grid_l because it is contained by the ScrollView).
When you add widgets to a non-layout widget, it's up to you to layout those widgets by setting position and size. Note that you must set the actual pos (or x and y) and size (or width and height) - you cannot use pos_hint or size_hint, as those are only handled by layouts.
code :
    image_source: ''
    subtext: ''
        height: self.parent.height  # match the button's height
        width: 100                  # set to whatever you would like
        pos: self.parent.pos        # match the button's position
        cols: 1
            source: root.image_source
            text: root.subtext
from kivy.factory import Factory
for i in range(3):
    btn = Factory.CustomButton(text=str(i), size_hint=(1, None),
                               image_source='kivy.png', subtext='label')
        id: gridlayoutID
        cols: 1
        size_hint: 1, None
        row_default_height: 40
        row_force_default: False
        height: self.minimum_height   # bind height to minimum_height
        width: self.minimum_width     # bind width to minimum_width

How do I add buttons that are dynamically created in pure python to a kivy layout that is Written in Kivy Language?

By : berhardt woods
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further My problem is that I need to create a grid of buttons based on a variable number of grid squares, and place them on a grid layout and display them on a screen using the screen manager. I know how to do this in pure python using a simple for loop, but I wrote the layout for my program in kivy language, and I don't know how to add the buttons to the grid layout, because I don't know how to correctly reference them in the kv file. The relevant python code is: , I hope this example makes it clear for you:
code :
#:kivy 1.9.0

    name: 'map'

        id: grid
        cols: 1
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from kivy.app import App
from kivy.uix.screenmanager import Screen
from kivy.uix.button import Button
from kivy.clock import mainthread


class MapScreen(Screen):

    def on_enter(self):
        for i in xrange(NUMBER_OF_BUTTONS):
            button = Button(text="B_" + str(i))

class Test(App):


How to put images into a dynamic text in Kivy

By : Si Jewell
Date : March 29 2020, 07:55 AM
seems to work fine Wraping
I haven't found any specific wrapping tool in kivy to solve your problem, so I've written a temporary function for that. Ideally I believe there should be a TextMarkup option to allow embedding images within the text, or even a separate widget, but for now this will be better than nothing.
code :
def wrap_text(target, source):
    text = source.split("|")

    for i in range(0, len(text)):
        if "img=" in text[i]:
class Main(App):

    def build(self):
        base = Builder.load_file("Main.kv")

        text_field = "This is text, below it should be the first image|img=example_1.png|" \
                     "Whereas this text should appear in between the images|img=example_2.png|" \
                     "And this text under the second image"

        wrap_text(base, text_field)

        return base
    orientation: 'vertical'
# Initialise a new, empty string, to add to it later
text = ""

# Iterate over widget's children (might as well dynamically assign them an id to find them faster)
for widget in rv.data[index]['description'].walk():

    # Add text if a label is found
    if isinstance(widget, Label):
        text += widget.text

# Assign the text to the field
rv.text_selected = text

Dynamic chanching images in kivy

By : user3151039
Date : March 29 2020, 07:55 AM
hope this fix your issue I want to change image in kv file every time when I click button. The problem is i have one image which is changing every time when you clik on the button, but the image stays the same , This worked:
code :
class RandomWindow(Screen,Widget):

def randomDrink(self):
    r = requests.get(photo,stream=True, headers={'User-agent': 'Mozilla/5.0'})

    if r.status_code == 200:
        with open("img.jpg", 'wb') as f:
            r.raw.decode_content = True
            shutil.copyfileobj(r.raw, f)

    id: im

Is there a simple way to add a border to Kivy Labels, Buttons, Widgets etc. with-out images?

By : NellyP
Date : March 29 2020, 07:55 AM
like below fixes the issue OK, I've found the fix. It was a naming conflict.
In the console log I saw that there is a problem at unpacking the border tuple in BorderImage of the button. Of course, that's not working because my border is implemented differently. Maybe I can add the list (top, right, bottom, left) to my border implementation so I can keep the same name. But I haven't checked that yet.
Related Posts Related Posts :
  • How do I capitalize each parameter in a function definition using Python?
  • Regex matching of a bytes pattern gives unusual results - '.' not equivalent to [\x00-\xff]
  • I need help converting this REST API Curl command to Python requests
  • How do you make a variable comparison to decide a better score in a dice game?
  • How do I run sumo-gui on instant-veins-4.7.1-i1.ova
  • Deal with NAN values when creating models with python
  • Python requests: having a space in header for posting
  • Adding a column to a pandas dataframe based on cell values
  • Get mongod rs.status() results from a python script
  • ImportError: C extension: No module named 'parsing' not built
  • python pandas update column values related to previous updated row during iteration over it
  • 3 nested loops: Optimizing a simple simulation for speed
  • Assign subset of values to pandas dataframe with MultiIndex
  • How to group two sets of buttons on each top corner of the screen using Tkinter?
  • django login using class based for custom user
  • MRJob sort reducer output
  • Python Pandas Counts using rolling time window
  • Getting or editing a string from a column in a csv file with pandas
  • Python - Delete row in matrix/array if row contains
  • Using dicom Images with OpenCV in Python
  • Odoo ghost record
  • Creating and assigning multiple variables in a tkinter application
  • Graph dictionary
  • No changes to original dataframe after applying loop
  • AUC of Random forest model is lower after tuning parameters using hypergrid search and CV with 10 folds
  • Python: Reading multiple CSV files, and assigning each to a different variable
  • How to identify empty rectangle using OpenCV
  • How to iterate multilevel dataframe in python
  • How to limit the contour plot with a line plot?
  • Why subclassing a str or int behaves differently from subclising a list or dict?
  • Python decode with translation table
  • i need to click unordered links in the below URL using selenium, python
  • How to join pandas dataframe with itself?
  • How to apply a color cast to a video frame in OpenCV Python?
  • Is there any existing library for median filtering with kernel size greater then 5 using OpenCL acceleration in python?
  • Changing the color of points in scatter plot for different dummy values
  • Calculate center for each polygon in a list efficiently
  • Loading modules in the same Python package
  • replacing pixels in an imagewith pixels from another image python
  • Suggestion on picking the best options of two lists (minimum and maximum )python
  • Resetting Index in a Dataframe drops the Indexed column by 1 row
  • Convert number which are str from readlines to digits - python
  • Unable to authenitcate with python minds api
  • Print variables from a query in python
  • Ipython does not see the installed library
  • Javascript-like array-method chaining in Python?
  • PyQT: Get contents CustFormWidgetIem inside QListWidgetItem
  • Bottle server: HTTPResponse vs bottle.response
  • pytorch vgg model test on one image
  • Runtime scope and `main` symbol is different inside or outside a function
  • Use anaconda in pycharm (Import libraries error, updating anaconda and virtual environment)
  • how to get the sum of a CSV column list to print
  • Python plot drop lines with repeating value in column
  • receive binary file from POST request with BaseHTTPRequestHandler
  • D-Bus - 'ServiceUnknown' exception encountered while calling a remote procedure
  • Pandas .min() method doesn't seem fastest
  • Pandas: How to reference columns of structure: ('Name', n) ('Name', n+1)
  • Read a text file and remove all characters except alphabets & spaces in Python
  • Compute all powerset intersections of two lists
  • Applying literal_eval on string of lists of POS tags gives ValueError
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org