Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Change the output Label text colour to pink (color is an RGBA tuple). Change the orientation so the widgets display left-to-right instead of top-to-bottom. Add

Change the output Label text colour to pink (color is an RGBA tuple).

Change the orientation so the widgets display left-to-right instead of top-to-bottom.

Add a label at the bottom with the text: Enter a number and press "Square".

To do this you will need to use nested layouts. There are two 'sections', made with BoxLayout, arranged vertically:

In the top section (BoxLayout), there are three widgets, arranged horizontally.

In the bottom section, there is just one label.

A good way to think about organising BoxLayouts is to draw boxes to represent them. You can have multiple widgets and/or BoxLayouts arranged within a BoxLayout.

So, in the example image here (Convert Miles to Kilometres), you should notice that the Up and Down buttons are vertically arranged within a BoxLayout (the green box).

This green layout is horizontally arranged next to a TextInput, so these must be inside another BoxLayout (the blue box).

This blue layout (the top third) is vertically arranged along with the "Convert" button and the label below it inside yet another BoxLayout (the red box).

The red BoxLayout will be the top-level, or root, widget. Nice...

squaring.kv BoxLayout: orientation: 'vertical' TextInput: id: input_number text: '7' font_size: 48 multiline: False Button: text: 'Square' # the following line specifies the function in the app class to call when the button is pressed on_press: app.handle_calculate(input_number.text) Label: id: output_label font_size: 48 color: (255,192,203)

squaring.py

""" CP1404/CP5632 Practical Kivy GUI program to square a number Lindsay Ward, IT@JCU Started 13/10/2015 """ from kivy.app import App from kivy.lang import Builder from kivy.core.window import Window __author__ = 'Lindsay Ward' class SquareNumberApp(App): """ SquareNumberApp is a Kivy App for squaring a number """ def build(self): """ build the Kivy app from the kv file """ Window.size = (200, 100) self.title = "Square Number" self.root = Builder.load_file('squaring.kv') return self.root def handle_calculate(self, value): """ handle calculation (could be button press or other call), output result to label widget """ try: result = float(value) ** 2 self.root.ids.output_label.text = str(result) except ValueError: pass SquareNumberApp().run()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions

Question

Apply Phase

Answered: 1 week ago

Question

Types of Interpersonal Relationships?

Answered: 1 week ago

Question

Self-Disclosure and Interpersonal Relationships?

Answered: 1 week ago