84292

Making a background canvas in kivy

Question:

I've read the questions about how to change a background, add a color, etc. in Kivy, and I'm familiar with how to do that for widgets.

My question is sort of a general strategy of what sort of object is intended to be used when all I want is a background that I'm going to put other widgets on---should that be a label or a widget, or a layout? (Suppose I'm only going to have a small padded background that I'll put a different colored gridlayout on, as in <a href="https://stackoverflow.com/questions/20366779/nesting-widgets-in-kivy" rel="nofollow">this question</a>.)

Answer1:

I think the answer is really 'it depends'. As you say, you can add a background to anything, so the decision rests entirely on what kind of other behaviour you want the widget to have.

<blockquote>

all I want is a background that I'm going to put other widgets on---should that be a label or a widget, or a layout?

</blockquote>

If you want totally no extra behaviour, a Widget is fine. If you want simple behaviour like having the child automatically placed/size to fill the background widget, then of course a simple layout like BoxLayout will be ideal. Alternatively, you might want (for instance) the child to be made a little smaller than the background widget in order to get a little border, in which case an AnchorLayout would be just right. Or for arbitrary proportional behaviour, the FloatLayout is ideal.

Of course you can see there, the question really comes down to 'do you want layout behaviour', and if so you just pick the layout that does what you want. There's absolutely no limitation and rule, and it's in the design of kivy that you can combine behaviours like this to get precisely what you want.

<blockquote>

(Suppose I'm only going to have a small padded background that I'll put a different colored gridlayout on, as in this question.)

</blockquote>

In this case, an <a href="http://kivy.org/docs/api-kivy.uix.anchorlayout.html" rel="nofollow">AnchorLayout</a> seems ideal. This lets you set a padding for the child widget, but (by default) it's otherwise centered, so if you make your own AnchorLayout subclass with a background you'll get the border you seem to want.

Recommend

  • Python String to Escaped Hex
  • String.padStart() not applying in Angular function
  • Python Convert unusual date string to datetime format
  • Setting rowcount and column count for grid layout dynamically
  • Add value “001” to mysql database
  • How to interchange between 2 timers? in Java GUI
  • Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException if-statement
  • JPanel and JButton, cannot figure how to layout 2 simple buttons
  • Javascript not loading wordpress footer
  • Django all-auth Form errors not displaying
  • Dynamically creating HTML button control and nesting i tag within it
  • Azure deployment continually recycling since upgrading the June 2012 SDK 1.7
  • css font-size and line-height not matching the baseline
  • Hibernate in Glassfish - Ejb3Configuration NoClassDefFoundError
  • Save website uploads in a subdomain
  • Cursor in wrong place in contenteditable
  • Can I have a variable number of URI parameters or key-value pairs in Laravel 4?
  • Spring integration inbound-gateway Fire an event when queue is empty
  • Two Tables Serving as one Model in Rails
  • Cloud Code function running twice
  • WPF version of .ScaleControl?
  • as3-flash: any way to access all the instances placed in different frames from document class?
  • Android Activity.onWindowFocusChanged doesn't get called from within TabHost
  • JqueryMobile Popup menu is not working
  • Multicolored edittext hint
  • Reduction and collapse clauses in OMP have some confusing points
  • SharedPreferences or SQLite Database?
  • Does it make sense to call System.gc() and Thread.sleep() when working on Bitmaps?
  • Android - Material Design - NavigationView - How to put vertical scroll?
  • Caching attributes in superclass
  • Using $this when not in object context
  • Uncaught Error: Could not find module `ember-load-initializers`
  • Jquery - Jquery Wysiwyg return html as a string
  • align graphs with different xlab
  • Arrays break string types in Julia
  • Cannot Parse HTML Data Using Android / JSOUP
  • WPF Applying a trigger on binding failure
  • Java static initializers and reflection
  • Programmatically clearing map cache
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize