Kivy: Change Button Color Part 1

This is how I finally figured out the best way to change the font and background color in the .kv file:

I was able to set the perimeters for all the buttons in my app on every screen by putting this at the top of my .kv file.

What’s going on?

  1. <Button> → This is not a screen, it refers to the built in Button class in Kivy and will standardize all buttons in your app. You can do the same thing with TextInput, etc.
  2. color: → font color.
  3. 1, 1, 1, 1 → the way Kivy manages color using rgba model. 1, 1, 1, 1, will give you white. rgba means red, green, blue, alpha. It refers to how much red or green or blue. The alpha refers to the opacity. 0 being clear and 1 being completely opaque. Most color pickers only use the 0 to 255 model (as you’ve probably already seen). To get variations I recommend using this site: https://rgbacolorpicker.com/. Then divide the number that you choose for each rgb by 255. In my opinion, quickly using my phone’s calculator is much quicker than searching for a converter online. See the example below:

This is the way to visualize the process of changing to decimals:

r =136/255 = 0.53

g = 255/255 = 1

b = 98/255 = 0.38

I always round to two decimal places. The Kivy notation for this specific color would be

(0.53, 1, 0.38, 0.31)

Back to my example:

4) background_color: 0, 1, 0, 1 →See below my color. The twist is that the kivy buttons are already have a dark color and shows through regardless. My green should look like this:

It ends up looking like this:

If you happen to know how to fix this problem, please put it in the comments.

--

--

--

I am a librarian and new computer programmer creating an app with Python and Kivy to document the plants in my garden.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Build a Go REST API with Fiber and MongoDB

Hackerrank Exercises

Razorpay Payment Gateway Integration — Oracle Apex 20.x

Creating Modular Waypoint System (part 1)

Golem Alpha.3 Provider Bounties

It begins with a Promise

The Meaning of Computation

Web3 Foundation Grants — Wave 12 Recipients

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rachela

Rachela

I am a librarian and new computer programmer creating an app with Python and Kivy to document the plants in my garden.

More from Medium

Oracle APEX: Install other languages

GPU Compute Shaders part 2 — fluids

Windows Keyboard Shortcut Keys