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.
Cannot assign string to object in ui
-
Hi all,
I’m extremely new to python and coding in general. I am trying to create a fairly simple app to clock in and out for work purposes. I have the ui show my “time card” which I want to have a running digital clock at the top of the screen. I can get the time and have it update every second but am having issues sending the string to an (any) object in my ui. Perhaps I’m not using the correct object to display my string or not using the correct code to send it. The error I keep getting is “ui.View” object does not support item assignment. My code looks something like this:
import ui import time def change_view(sender): '@type sender: ui.Button' #get button name: b = sender.name v = ui.load_view(b) return v.present() @ui.in_background def update_time(): while True: time.sleep(1) v1['clock_view'] = time.strftime('%r') v1 = ui.load_view('time_card') update_view() v1.present() ```
-
@cjohnson32 As we don't see the ui file, I'll suppose, as example, that your object named clock_view is an ui.Label where you want to display the time. Thus you have to store the string in the right attribute, in this case "text", thus you have to type
v1['clock_view'].text = time.strftime('%r')
-
@cvp that was exactly what I needed. I thought label is what should be used but had no success sending my string. Turns out I was only missing the .text - Thank you!
-
This post is deleted!