In: Computer Science
Python.
1.Why is it a good idea to write and test the code for laying out a window's components before you add the methods that perform computations in response to events?
2.Explain why you would not use a text field to perform input and output of numbers.
3.Write a line of code that adds a FloatField to a window, at position (1, 1) in the grid, with an initial value of 0.0, a width of 15, and a precision of 2.
4.What happens when you enter a number with a decimal point into an IntegerField?
5.When would you make a data field read-only, and how would you do this?
1.Window components are often laid and tested before adding to the computation in perform of events so that its feel and look can be checked individually and the corresponding event handlers performance can also be reviewed
2.If the text field is used for input and output of numbers, the data needs to be converted to string after the input is stored and also before output is produced. To simplify this task of the compiler, the IntegerField and FloatField are used which provides a value attribute in advance to the data.
3.The correct code for displaying this is
self.addFloatField(initial value,row grid value, column grid value,width, precision,type)
here initial value=(0,0)
row grid value=1
column grid value=1
width=15
precision=2
Therefore, the code becomes
self.addFloatField(value=0.0,row=1,column=1,width=15,precision=2);
4. The only difference between the integerfield and floatfield is the amount of characters it can take. IntegerField can take width of 10 whereas FloatField can take value of 20. Moreover float field has an additional precision element . The data is processed equally by both of them.