Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
How do I get my code to interact with the ui TextFields?
-
So I'm trying to make a program that calculates the unit weight of concrete cylinder specimens given two different weights and the temperature of water used to measure one of the weights, and I can't seem to get the data that I put in the textfields to variables in the code.
When I run the code, I get these errors in the console:
"Warning: Could not bind action: name 'volumeField_action' is not defined"
Then again for 'unitWeightField_action' and 'calculateButton_action'Can someone please tell me what I'm doing wrong?
Thank you <3import ui import math table = ( 0.998120,0.998398,0.998650,0.998877,0.999080,0.999259,0.999417,0.999553,0.999669,0.999765, 0.9998425,0.9999015,0.9999429,0.9999672,0.9999750,0.9999668,0.9999432,0.9999045,0.9998512,0.9997838, 0.9997026,0.9996018,0.9995004,0.9993801,0.9992474,0.9991026,0.9989460,0.9987779,0.9985986,0.9984082, 0.9982071,0.9979955,0.9977735,0.9975415,0.9972995,0.9970479,0.9967867,0.9965162,0.9962365,0.9959478, 0.9956502,0.9953440,0.9950292,0.9947060,0.9943745,0.9940349,0.9936872,0.9933316,0.9929683,0.9925973, 0.9922187,0.9918327,0.9914394,0.9910388,0.9906310,0.9902162,0.9897944,0.9893657,0.9889303,0.9884881, 0.9880393,0.9875839,0.9871220,0.9866537,0.9861791,0.9856982,0.9852111,0.9847178,0.9842185,0.9837132, 0.9832018,0.9826846,0.9821615,0.9816327,0.9810981,0.9805578,0.9800118,0.9794603,0.9789032,0.9783406, 0.9777726,0.9771991,0.9766203,0.9760361,0.9754466,0.9748519,0.9742520,0.9736468,0.9730366,0.9724212, 0.9718007,0.9711752,0.9705446,0.9699091,0.9692686,0.9686232,0.9679729,0.9673177,0.9666576,0.9659927, 0.9653230,0.9646486,0.9639693,0.9632854,0.9625967,0.9619033,0.9612052,0.9605025,0.9597951,0.9590831, 0.9583665,0.957662,0.956937,0.956207,0.955472,0.954733,0.953989,0.953240,0.952488,0.941730 ) def waterdensity(t): t = (t - 32.0) / 1.8 i = math.floor(t) p = t - i p2m1 = p * p - 1.0 p2m4 = p2m1 - 3.0 i += 10 return (p2m1*p*(p-2)*table[i-2]/24.0 - (p-1)*p*p2m4*table[i-1]/6.0 + p2m1*p2m4*table[i]/4.0 - (p+1)*p*p2m4*table[i+1]/6.0 + p2m1*p*(p+2)*table[i+2]/24.0) * 62.427961 v = ui.load_view() v.background_color = "white" v.present('sheet') temp = 70.0 tempField = v['tempField'] def tempField_action(sender): temp = sender.text return temp tempField.action = tempField_action SSD = 1.0 SSDField = v['SSDField'] def SSDField_action(sender): SSD = sender.text return SSD SSDField.action = SSDField_action weightWater = 1.0 weightWaterField = v['weightWaterField'] def weightWaterField_action(sender): weightWater = sender.text return weightWater weightWaterField.action = weightWaterField_action volume = 1.0 volumeField = v['volumeField'] volumeField.enabled = False def volumeField_action(sender): volume = (SSD - weightWater) / waterdensity(temp) vsender.text = sender.text return volume volumeField.action = volumeField_action unitWeight = 1.0 unitWeightField = v['unitWeightField'] unitWeightField.enabled = False def unitWeightField_action(sender): unitWeight = SSD / volume sender.text = unitWeight return unitWeight unitWeightField.action = unitWeightField_action calculateButton = v['calculateButton'] def calculateButton_action(sender): volumeField.action unitWeightField.action calculateButton.action = calculateButton_action
-
When using the UI designer and load_view, you need you have all of your callbacks defined before you call load_view. That's why you are getting the binding warnings.
Just define your callback actions at the beginning.
Also... Actions don't return values. Try print if you want to test...
-
@Julian8941 did you also define action in UI file? If yes, these are not yet known when you load_view your UI
-
@JonB we cross.. In French "les grands esprits se rencontrent"
-
Great minds think alike.
-