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.
Easy way to display formatted text
-
I have a script that outputs some text to the console and all I want to do is display it in a specific size and font. It appears I could use Scene, UI, Hydrogen, HTML (to the internal browser), and maybe other ways. What is the simplest way? Does anyone have a code snippet to share?
-
The
console
module has theset_font
andset_color
functions, which are probably the easiest way to "upgrade" your script to output formatted text. -
You can do it with the
console
module. Example:console.set_font('Zapfino', 48) console.set_color(1.00, 0.50, 0.00) print 'Hello' console.set_font() console.set_color(0.00, 0.00, 0.00) print 'world!'
-
@dgelessus, @Gerzer Very helpful, thanks. Now if I want to go a step further and dynamically update a displayed value, what do you recommend using?
-
Really low budget animation via
console.clear()
.import console, time for i in xrange(10): for char in '/-\\|': console.clear() print(char) time.sleep(0.25)
-
@ccc That may be a bit lower budget than I was seeking :-) Next step up?
-
-
Sorry if this is a very basic question but if I were to use ui, then I presume I want to use the label object? If so, can you give me a script fragment that would display the value of a variable as a label created in the UI designer?
-
What I came up with:
import ui v=ui.load_view('My UI') v['label1'].text='Text to display' v.present('sheet')
Does this look reasonable?
-
Looks like all the right stuff to me. If you want to see dynamic updating of the text you could
import time
and add the following two lines to the end of your code above:while v.on_screen: v['label1'].text= 'The current time is: {}'.format(time.ctime())
You will probably need to go into the UI Designer and stretch your label to the right to see all the text.
My strong recommendation at this point is that you check out the
UI Tutorial
examples in the UI section of Pythonista Tools. It is a great way to learn the ui module and there are great tips and tricks there. You can submit pull requests if you have ideas for improving that content.