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?
Forum Archive
Easy way to display formatted text
The console module has the set_font and set_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:
import console
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?
http://omz-software.com/pythonista/docs/ios/ui.html ;-)
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.